aboutsummaryrefslogtreecommitdiff
path: root/pkcs8.py
diff options
context:
space:
mode:
Diffstat (limited to 'pkcs8.py')
-rw-r--r--pkcs8.py124
1 files changed, 62 insertions, 62 deletions
diff --git a/pkcs8.py b/pkcs8.py
index cd45ff6..295fbb4 100644
--- a/pkcs8.py
+++ b/pkcs8.py
@@ -177,80 +177,80 @@ if __name__ == "__main__":
rsa_pkcs8 = DER_Decode(der_test_keys["rsa_pkcs8"], PrivateKeyInfo())[0]
rsa_pkcs8_privateKey = DER_Decode(str(rsa_pkcs8["privateKey"]), RSAPrivateKey() )[0]
- print
- print "EC RFC 5915"
- print ec_rfc5915.prettyPrint()
+ print()
+ print("EC RFC 5915")
+ print(ec_rfc5915.prettyPrint())
if show_manual_decode:
- print
+ print()
compressed, Qx, Qy = decode_ecpoint(ec_rfc5915["publicKey"].asOctets())
- print "version: ", ec_rfc5915["version"]
- print "privateKey:", str(ec_rfc5915["privateKey"]).encode("hex")
- print "parameters:", ec_rfc5915["parameters"]
- print "publicKey: ", compressed
- print " Qx: ", Qx.encode("hex")
- print " Qy: ", Qy.encode("hex")
+ print("version: ", ec_rfc5915["version"])
+ print("privateKey:", str(ec_rfc5915["privateKey"]).encode("hex"))
+ print("parameters:", ec_rfc5915["parameters"])
+ print("publicKey: ", compressed)
+ print(" Qx: ", Qx.encode("hex"))
+ print(" Qy: ", Qy.encode("hex"))
# This works, and lets .prettyPrint() display the ANY content properly,
# but it breaks some of the key hackery we do after all this display stuff.
#ec_pkcs8["privateKeyAlgorithm"]["parameters"] = DER_Decode(ec_pkcs8["privateKeyAlgorithm"]["parameters"])[0]
- print
- print "EC PKCS #8"
- print ec_pkcs8.prettyPrint()
- print ec_pkcs8_privateKey.prettyPrint()
+ print()
+ print("EC PKCS #8")
+ print(ec_pkcs8.prettyPrint())
+ print(ec_pkcs8_privateKey.prettyPrint())
if show_manual_decode:
- print
+ print()
compressed, Qx, Qy = decode_ecpoint(ec_pkcs8_privateKey["publicKey"].asOctets())
- print "version: ", ec_pkcs8["version"]
- print "privateKeyAlgorithm:", ec_pkcs8["privateKeyAlgorithm"][0]
- print " ", DER_Decode(ec_pkcs8["privateKeyAlgorithm"]["parameters"])[0]
- print "privateKey:"
- print " version: ", ec_pkcs8_privateKey["version"]
- print " privateKey:", str(ec_pkcs8_privateKey["privateKey"]).encode("hex")
- print " parameters:", ec_pkcs8_privateKey["parameters"]
- print " publicKey: ", compressed
- print " Qx: ", Qx.encode("hex")
- print " Qy: ", Qy.encode("hex")
-
- print
- print "RSA RFC 2313"
- print rsa_rfc2313.prettyPrint()
+ print("version: ", ec_pkcs8["version"])
+ print("privateKeyAlgorithm:", ec_pkcs8["privateKeyAlgorithm"][0])
+ print(" ", DER_Decode(ec_pkcs8["privateKeyAlgorithm"]["parameters"])[0])
+ print("privateKey:")
+ print(" version: ", ec_pkcs8_privateKey["version"])
+ print(" privateKey:", str(ec_pkcs8_privateKey["privateKey"]).encode("hex"))
+ print(" parameters:", ec_pkcs8_privateKey["parameters"])
+ print(" publicKey: ", compressed)
+ print(" Qx: ", Qx.encode("hex"))
+ print(" Qy: ", Qy.encode("hex"))
+
+ print()
+ print("RSA RFC 2313")
+ print(rsa_rfc2313.prettyPrint())
if show_manual_decode:
- print
- print "version:", rsa_rfc2313["version"]
- print " n:", rsa_rfc2313["n"]
- print " e:", rsa_rfc2313["e"]
- print " d:", rsa_rfc2313["d"]
- print " p:", rsa_rfc2313["p"]
- print " q:", rsa_rfc2313["q"]
- print " dP:", rsa_rfc2313["dP"]
- print " dQ:", rsa_rfc2313["dQ"]
- print " u:", rsa_rfc2313["u"]
+ print()
+ print("version:", rsa_rfc2313["version"])
+ print(" n:", rsa_rfc2313["n"])
+ print(" e:", rsa_rfc2313["e"])
+ print(" d:", rsa_rfc2313["d"])
+ print(" p:", rsa_rfc2313["p"])
+ print(" q:", rsa_rfc2313["q"])
+ print(" dP:", rsa_rfc2313["dP"])
+ print(" dQ:", rsa_rfc2313["dQ"])
+ print(" u:", rsa_rfc2313["u"])
#rsa_pkcs8["privateKeyAlgorithm"]["parameters"] = DER_Decode(rsa_pkcs8["privateKeyAlgorithm"]["parameters"])[0]
- print
- print "RSA PKCS #8"
- print rsa_pkcs8.prettyPrint()
- print rsa_pkcs8_privateKey.prettyPrint()
+ print()
+ print("RSA PKCS #8")
+ print(rsa_pkcs8.prettyPrint())
+ print(rsa_pkcs8_privateKey.prettyPrint())
if show_manual_decode:
- print
- print "version: ", rsa_pkcs8["version"]
- print "privateKeyAlgorithm:", rsa_pkcs8["privateKeyAlgorithm"][0]
- print "privateKey:"
- print " version:", rsa_pkcs8_privateKey["version"]
- print " n:", rsa_pkcs8_privateKey["n"]
- print " e:", rsa_pkcs8_privateKey["e"]
- print " d:", rsa_pkcs8_privateKey["d"]
- print " p:", rsa_pkcs8_privateKey["p"]
- print " q:", rsa_pkcs8_privateKey["q"]
- print " dP:", rsa_pkcs8_privateKey["dP"]
- print " dQ:", rsa_pkcs8_privateKey["dQ"]
- print " u:", rsa_pkcs8_privateKey["u"]
+ print()
+ print("version: ", rsa_pkcs8["version"])
+ print("privateKeyAlgorithm:", rsa_pkcs8["privateKeyAlgorithm"][0])
+ print("privateKey:")
+ print(" version:", rsa_pkcs8_privateKey["version"])
+ print(" n:", rsa_pkcs8_privateKey["n"])
+ print(" e:", rsa_pkcs8_privateKey["e"])
+ print(" d:", rsa_pkcs8_privateKey["d"])
+ print(" p:", rsa_pkcs8_privateKey["p"])
+ print(" q:", rsa_pkcs8_privateKey["q"])
+ print(" dP:", rsa_pkcs8_privateKey["dP"])
+ print(" dQ:", rsa_pkcs8_privateKey["dQ"])
+ print(" u:", rsa_pkcs8_privateKey["u"])
# Generate PKCS #8 from ECPrivateKey and check against static data
p8 = PrivateKeyInfo()
@@ -266,7 +266,7 @@ if __name__ == "__main__":
der = DER_Encode(p8)
#print; dumpasn1(der)
#print; dumpasn1(der_test_keys["ec_pkcs8"])
- print; print "Reencoded PKCS #8 {} static data".format("matches" if der == der_test_keys["ec_pkcs8"] else "doesn't match")
+ print(); print("Reencoded PKCS #8 {} static data".format("matches" if der == der_test_keys["ec_pkcs8"] else "doesn't match"))
# Try doing same thing with ecdsa package ASN.1 utilities.
sk = SigningKey.from_der(der_test_keys["ec_rfc5915"])
@@ -278,7 +278,7 @@ if __name__ == "__main__":
ECDSA_DER.encode_sequence(encoded_oid_ecPublicKey,
sk.curve.encoded_oid),
ECDSA_DER.encode_octet_string(ec))
- print; print "ECDSA-library PKCS #8 encoding {} pyasn1 PKCS #8 encoding".format("matches" if p8 == der_test_keys["ec_pkcs8"] else "doesn't match")
+ print(); print("ECDSA-library PKCS #8 encoding {} pyasn1 PKCS #8 encoding".format("matches" if p8 == der_test_keys["ec_pkcs8"] else "doesn't match"))
# Generate ECPrivateKey from PKCS #8 and check against static data
ec = ECPrivateKey()
@@ -289,11 +289,11 @@ if __name__ == "__main__":
der = DER_Encode(ec)
#print; dumpasn1(der)
#print; dumpasn1(der_test_keys["ec_rfc5915"])
- print; print "Reencoded PKCS #8 {} static data".format("matches" if der == der_test_keys["ec_rfc5915"] else "doesn't match")
+ print(); print("Reencoded PKCS #8 {} static data".format("matches" if der == der_test_keys["ec_rfc5915"] else "doesn't match"))
# Paranoia: Make sure we really can load the RFC 5915 we just generated.
sk = SigningKey.from_der(der)
- print; print "ECDSA Python library parse of reencoded PKCS #8 data: {!r}".format(sk)
+ print(); print("ECDSA Python library parse of reencoded PKCS #8 data: {!r}".format(sk))
# Same thing with ecdsa package ASN.1 utilities.
car, cdr = ECDSA_DER.remove_sequence(der_test_keys["ec_pkcs8"])
@@ -320,5 +320,5 @@ if __name__ == "__main__":
assert cdr == ""
assert pubkey[:2] == "\x00\x04"
sk = SigningKey.from_string(privkey, curve)
- print; print "ECDSA-library PKCS #8 decoding {} pyasn1 PKCS #8 decoding".format(
- "matches" if der == sk.to_der() else "doesn't match")
+ print(); print("ECDSA-library PKCS #8 decoding {} pyasn1 PKCS #8 decoding".format(
+ "matches" if der == sk.to_der() else "doesn't match"))