本文整理汇总了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)