Esempio n. 1
0
def test():
    print "\t-------------"
    print "\tTesting PKCS1"
    print "\t-------------"
    _key = RSA.generate(1024, cryptrand.random)
    key = RSA_pkcs1(_key)

    plain = "i am un chien andalusia"
    print "\tTesting (encrypt-public/decrypt)... " + plain
    cipher = key.encryptPublic(plain)
    decip = key.decryptPrivate(cipher)
    assert plain == decip, "pisces.pkcs1: Encrypt public/decrypt private failed"

    plain = "this monkey's gone to heaven"
    print "\tTesting (encrypt-private/decrypt)... " + plain
    cipher = key.encryptPrivate(plain)
    decip = key.decryptPublic(cipher)
    assert plain == decip, "pisces.pkcs1: Encrypt private/decrypt public failed"

    # test asn.1 support for DigestInfo
    global x, buf, y
    print "\tTesting ASN.1 Support for DigestInfo encode/decode"
    x = DigestInfo(algid.AlgorithmIdentifier([algid.oid_md5, None]), "x" * 16)
    buf = x.encode()
    y = asn1.parse(buf)
    assert x == y, "pisces.pkcs1: DigestInfo encode/decode failed"

    print "\tTesting PKCS1 Signature Verification"
    signer = MD5withRSA(key)
    verifier = MD5withRSA(key)
    sig = signer.sign("foo")
    assert verifier.verify("foo", sig) == 1, "pisces.pkcs1: Signature verification failed"
    print "\n\n\t------------------"
    print "\tEND OF PKCS1 TESTS"
    print "\t------------------"
Esempio n. 2
0
 def verify(self, data, sig):
     enc = self.key.decryptPublic(sig)
     try:
         parsed = asn1.parse(enc)
     except ValueError:
         return 0
     dig = DigestInfo(parsed)
     if dig.digestAlgorithm != self._digAlgId:
         raise ValueError, "unexpected digest algorithm: %s" % str(dig.digestAlgorithm)
     md = self.digest(data)
     if md == dig.digest:
         return 1
     return 0
Esempio n. 3
0
def test():
    global x, buf, y
    x = AlgorithmIdentifier(oid_rsa_md5, None)
    buf = x.encode()
    y = asn1.parse(buf)
    assert x == y, "pisces.algid: AlgorithmIdentifier encode/decode failed"
Esempio n. 4
0
def main():
    import sys
    import getopt

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'c:')
        for o, a in opts:
            if o == '-c':
                f = open(a)
                oids = asn1.parseCfg(f)
                f.close()
                display = asn1.Displayer(oids)
    except (getopt.error, IOError), msg:
        print "Error", msg
        print __doc__
        return

    for path in args:
        try:
            f = open(path, 'rb')
        except IOError, msg:
            print "Error", msg
            continue
        obj =  asn1.parse(f.read())
        f.close()
        print path
        display(obj)
    
if __name__ == "__main__":
    main()