keys.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:fastecdsa 作者: AntonKueltz 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号