本文整理匯總了Python中Crypto.PublicKey方法的典型用法代碼示例。如果您正苦於以下問題:Python Crypto.PublicKey方法的具體用法?Python Crypto.PublicKey怎麽用?Python Crypto.PublicKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Crypto
的用法示例。
在下文中一共展示了Crypto.PublicKey方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: import_key
# 需要導入模塊: import Crypto [as 別名]
# 或者: from Crypto import PublicKey [as 別名]
def import_key(encoded, passphrase=None):
# encoded, passphrase=None
# extern_key, passphrase=None
# key = Cryptodome.PublicKey.ECC.import_key(*args, **kwargs)
# return to_ecdsakey(key, _from=Cryptodome.PublicKey.ECC, _to=ecdsa.SigningKey)
if encoded.startswith('-----'):
return ecdsa.SigningKey.from_pem(encoded)
# OpenSSH
# if encoded.startswith(b('ecdsa-sha2-')):
# return _import_openssh(encoded)
# DER
if ord(encoded[0]) == 0x30:
return ecdsa.SigningKey.from_der(encoded)
raise Exception("Invalid Format")
示例2: to_dsakey
# 需要導入模塊: import Crypto [as 別名]
# 或者: from Crypto import PublicKey [as 別名]
def to_dsakey(secret_key, _from=Crypto.PublicKey.DSA, _to=Cryptodome.PublicKey.DSA):
if _from == Cryptodome.PublicKey.DSA:
return _to.construct((int(secret_key._key['y']),
int(secret_key._key['g']),
int(secret_key._key['p']),
int(secret_key._key['q']),
int(secret_key._key['x'])))
return _to.construct((secret_key.key.y,
secret_key.key.g,
secret_key.key.p,
secret_key.key.q,
secret_key.key.x))
示例3: to_ecdsakey
# 需要導入模塊: import Crypto [as 別名]
# 或者: from Crypto import PublicKey [as 別名]
def to_ecdsakey(secret_key, _from=ecdsa.SigningKey, _to=Cryptodome.PublicKey.ECC):
# pointx, pointy, d
return _to.import_key(secret_key.to_der())
示例4: export_key
# 需要導入模塊: import Crypto [as 別名]
# 或者: from Crypto import PublicKey [as 別名]
def export_key(self, *args, **kwargs):
# format='PEM', pkcs8=None, passphrase=None, protection=None, randfunc=None
return to_dsakey(self.privkey, _to=Cryptodome.PublicKey.DSA).exportKey(*args, **kwargs)