如何使用 pyasn1 解析 ec public?
from pyasn1.codec.der import decoder
import base64
raw2='''
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/FU6/Om2m5EnxDwGSVO+YNXorpDtzutLtCAMTZR5
NIs6pfKx9oyjpS5aURx4BinuW8dr8K7N2oafY1TNvc41oQ==
'''
der = decoder.decode(base64.b64decode(raw2))
print der
'''
der:
(Sequence().setComponentByPosition(0, Sequence().setComponentByPosition(0, ObjectIdentifier(1.2.840.10045.2.1)).setComponentByPosition(1, ObjectIdentifier(1.2.840.10045.3.1.7))).setComponentByPosition(1, BitString("'0000010011111100010101010011101011111100111010011011011010011011100100010010011111000100001111000000011001001001010100111011111001100000110101011110100010101110100100001110110111001110111010110100101110110100001000000000110001001101100101000111100100110100100010110011101010100101111100101011000111110110100011001010001110100101001011100101101001010001000111000111100000000110001010011110111001011011110001110110101111110000101011101100110111011010100001101001111101100011010101001100110110111101110011100011010110100001'B")), '')
'''
有没有可能,用 pyasn1得到这样的东西。
编辑: 我以此为基础获得以下内容:
class curve(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('public KeyType',univ.ObjectIdentifier()),
namedtype.NamedType('curveName',univ.ObjectIdentifier())
)
class EcPublicKey(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('curve', curve()),
namedtype.NamedType('publicKeyValue', univ.BitString())
)
pubKey,rest = decoder.decode(base64.b64decode(raw2), asn1Spec = EcPublicKey())
print(pubKey.prettyPrint())
'''
EcPublicKey:
curve=curve:
public KeyType=1.2.840.10045.2.1
curveName=1.2.840.10045.3.1.7
publicKeyValue="'0000010011111100010101010011101011111100111010011011011010011011100100010010011111000100001111000000011001001001010100111011111001100000110101011110100010101110100100001110110111001110111010110100101110110100001000000000110001001101100101000111100100110100100010110011101010100101111100101011000111110110100011001010001110100101001011100101101001010001000111000111100000000110001010011110111001011011110001110110101111110000101011101100110111011010100001101001111101100011010101001100110110111101110011100011010110100001'B"
'''