示例#1
0
from pyndn import NDN,Name,Interest,ContentObject,Key

k = Key()
k.generateRSA(1024)
del k
示例#2
0
import os, filecmp
from base64 import b64encode, b64decode
from pyndn import Key, _pyndn, NDN

k = NDN.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")
示例#3
0
def rm_files(*list):
    for file in list:
        if os.path.exists(file):
            os.remove(file)


rm_files(private_pem1, public_pem1, private_pem2, public_pem2)

k = NDN.getDefaultKey()

k.privateToPEM(filename=private_pem1)
k.publicToPEM(filename=public_pem1)

k2 = Key()
k2.fromPEM(filename=private_pem1)

k2.privateToPEM(filename=private_pem2)
k2.publicToPEM(filename=public_pem2)

assert filecmp.cmp(private_pem1, private_pem2)
assert filecmp.cmp(public_pem1, public_pem2)
print(b64encode(k.publicKeyID))
print(b64encode(k2.publicKeyID))
assert k.publicKeyID == k2.publicKeyID

del (k2)
rm_files(private_pem2, public_pem2)

k2 = Key()