当前位置: 首页>>代码示例>>Python>>正文


Python univ.BitString方法代码示例

本文整理汇总了Python中pyasn1.type.univ.BitString方法的典型用法代码示例。如果您正苦于以下问题:Python univ.BitString方法的具体用法?Python univ.BitString怎么用?Python univ.BitString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyasn1.type.univ的用法示例。


在下文中一共展示了univ.BitString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _key_identifier_from_public_key

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import BitString [as 别名]
def _key_identifier_from_public_key(public_key):
    # This is a very slow way to do this.
    serialized = public_key.public_bytes(
        serialization.Encoding.DER,
        serialization.PublicFormat.SubjectPublicKeyInfo
    )
    spki, remaining = decoder.decode(
        serialized, asn1Spec=_SubjectPublicKeyInfo()
    )
    assert not remaining
    # the univ.BitString object is a tuple of bits. We need bytes and
    # pyasn1 really doesn't want to give them to us. To get it we'll
    # build an integer and convert that to bytes.
    bits = 0
    for bit in spki.getComponentByName("subjectPublicKey"):
        bits = bits << 1 | bit

    data = utils.int_to_bytes(bits)
    return hashlib.sha1(data).digest() 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:21,代码来源:extensions.py

示例2: convertPKCS1toPKCS8pubKey

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import BitString [as 别名]
def convertPKCS1toPKCS8pubKey(bitsdata):
    pubkey_pkcs1_b64 = b''.join(bitsdata.split(b'\n')[1:-2])
    pubkey_pkcs1, restOfInput = der_decoder.decode(base64.b64decode(pubkey_pkcs1_b64))
    bitstring = univ.Sequence()
    bitstring.setComponentByPosition(0, univ.Integer(pubkey_pkcs1[0]))
    bitstring.setComponentByPosition(1, univ.Integer(pubkey_pkcs1[1]))
    bitstring = der_encoder.encode(bitstring)
    try:
        bitstring = ''.join([('00000000'+bin(ord(x))[2:])[-8:] for x in list(bitstring)])
    except:
        bitstring = ''.join([('00000000'+bin(x)[2:])[-8:] for x in list(bitstring)])
    bitstring = univ.BitString("'%s'B" % bitstring)
    pubkeyid = univ.Sequence()
    pubkeyid.setComponentByPosition(0, univ.ObjectIdentifier('1.2.840.113549.1.1.1')) # == OID for rsaEncryption
    pubkeyid.setComponentByPosition(1, univ.Null(''))
    pubkey_seq = univ.Sequence()
    pubkey_seq.setComponentByPosition(0, pubkeyid)
    pubkey_seq.setComponentByPosition(1, bitstring)
    base64.MAXBINSIZE = (64//4)*3
    res =  b"-----BEGIN PUBLIC KEY-----\n"
    res += base64.encodestring(der_encoder.encode(pubkey_seq))
    res += b"-----END PUBLIC KEY-----\n"
    return res 
开发者ID:iOSForensics,项目名称:pymobiledevice,代码行数:25,代码来源:ca.py

示例3: _key_identifier_from_public_key

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import BitString [as 别名]
def _key_identifier_from_public_key(public_key):
    if isinstance(public_key, RSAPublicKey):
        data = public_key.public_bytes(
            serialization.Encoding.DER,
            serialization.PublicFormat.PKCS1,
        )
    elif isinstance(public_key, EllipticCurvePublicKey):
        data = public_key.public_numbers().encode_point()
    else:
        # This is a very slow way to do this.
        serialized = public_key.public_bytes(
            serialization.Encoding.DER,
            serialization.PublicFormat.SubjectPublicKeyInfo
        )
        spki, remaining = decoder.decode(
            serialized, asn1Spec=_SubjectPublicKeyInfo()
        )
        assert not remaining
        # the univ.BitString object is a tuple of bits. We need bytes and
        # pyasn1 really doesn't want to give them to us. To get it we'll
        # build an integer and convert that to bytes.
        bits = 0
        for bit in spki.getComponentByName("subjectPublicKey"):
            bits = bits << 1 | bit

        data = utils.int_to_bytes(bits)

    return hashlib.sha1(data).digest() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:30,代码来源:extensions.py

示例4: realEncode

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import BitString [as 别名]
def realEncode(self, data):
            return der.encoder.encode(univ.BitString(data)) 
开发者ID:MozillaSecurity,项目名称:peach,代码行数:4,代码来源:ASN1.py

示例5: rsa_public_key_pkcs1_to_pkcs8

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import BitString [as 别名]
def rsa_public_key_pkcs1_to_pkcs8(pkcs1_key):
    """Convert a PKCS1-encoded RSA private key to PKCS8."""
    algorithm = RsaAlgorithmIdentifier()
    algorithm["rsaEncryption"] = RSA_ENCRYPTION_ASN1_OID

    pkcs8_key = PublicKeyInfo()
    pkcs8_key["algorithm"] = algorithm
    pkcs8_key["publicKey"] = univ.BitString.fromOctetString(pkcs1_key)

    return encoder.encode(pkcs8_key) 
开发者ID:mpdavis,项目名称:python-jose,代码行数:12,代码来源:_asn1.py


注:本文中的pyasn1.type.univ.BitString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。