Exemple #1
0
k2.publicToPEM(filename=public_pem2)

assert (filecmp.cmp(public_pem1, public_pem2))
assert (k.publicKeyID == k2.publicKeyID)

rm_files(private_pem1, public_pem1, private_pem2, public_pem2)

private = k.privateToPEM()
public = k.publicToPEM()

k2 = Key()
k2.fromPEM(private=private)

assert (k.privateToDER() == k2.privateToDER())
assert (k.publicToDER() == k2.publicToDER())
assert (k.publicKeyID == k2.publicKeyID)

k2 = Key()
k2.fromPEM(public=public)

try:
    k2.privateToPEM()
except:
    pass
else:
    raise AssertionError("This should fail - this is not a private key")

assert (k.publicToDER() == k2.publicToDER())
assert (k.publicKeyID == k2.publicKeyID)
Exemple #2
0
k2.publicToPEM(filename=public_pem2)

assert(filecmp.cmp(public_pem1, public_pem2))
assert(k.publicKeyID == k2.publicKeyID)

rm_files(private_pem1, public_pem1, private_pem2, public_pem2)

private = k.privateToPEM()
public = k.publicToPEM()

k2 = Key()
k2.fromPEM(private=private)

assert(k.privateToDER() == k2.privateToDER())
assert(k.publicToDER() == k2.publicToDER())
assert(k.publicKeyID == k2.publicKeyID)

k2 = Key()
k2.fromPEM(public=public)

try:
	k2.privateToPEM()
except:
	pass
else:
	raise AssertionError("This should fail - this is not a private key")

assert(k.publicToDER() == k2.publicToDER())
assert(k.publicKeyID == k2.publicKeyID)
Exemple #3
0
import os, filecmp
from base64 import b64encode, b64decode
from pyccn import Key, _pyccn, CCN

k = CCN.getDefaultKey()

private1_der = k.privateToDER()
public1_der = k.publicToDER()

k2 = Key()
k2.fromDER(private=private1_der)

private2_der = k2.privateToDER()
public2_der = k2.publicToDER()

assert(private1_der == private2_der)
assert(public1_der == public2_der)
assert(k.publicKeyID == k2.publicKeyID)

del(k2)

k2 = Key()
k2.fromDER(public=public1_der)

try:
	private2_der = k2.privateToDER()
except:
	pass
else:
	raise AssertionError("This should fail - this is not a private key")