def encode_public_key(Q):
header = '-----BEGIN PUBLIC KEY-----\n'
footer = '\n-----END PUBLIC KEY-----'
x_bytes = _int_to_bytes(Q.x)
y_bytes = _int_to_bytes(Q.y)
param_len = pack('=B', len(Q.curve.oid) + 2)
oid_len = pack('=B', len(Q.curve.oid))
key_data_len = pack('=B', len(x_bytes + y_bytes) + 4)
xy_len = pack('=B', len(x_bytes + y_bytes) + 2)
bit_string = '\x02\x01\x01\xa0{}\x06{}{}\xa1{}\x03{}\x00\x04{}{}'.format(
param_len, oid_len, Q.curve.oid, key_data_len, xy_len, x_bytes, y_bytes)
body = '\x30{}{}'.format(pack('=B', len(bit_string)), bit_string)
return header + '\n'.join(wrap(b2a_base64(body), 64)) + footer
评论列表
文章目录