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


Python utils.int_from_bytes方法代码示例

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


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

示例1: from_encoded_point

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def from_encoded_point(cls, curve, data):
        if not isinstance(curve, EllipticCurve):
            raise TypeError("curve must be an EllipticCurve instance")

        warnings.warn(
            "Support for unsafe construction of public numbers from "
            "encoded data will be removed in a future version. "
            "Please use EllipticCurvePublicKey.from_encoded_point",
            utils.PersistentlyDeprecated2019,
            stacklevel=2,
        )

        if data.startswith(b'\x04'):
            # key_size is in bits. Convert to bytes and round up
            byte_length = (curve.key_size + 7) // 8
            if len(data) == 2 * byte_length + 1:
                x = utils.int_from_bytes(data[1:byte_length + 1], 'big')
                y = utils.int_from_bytes(data[byte_length + 1:], 'big')
                return cls(x, y, curve)
            else:
                raise ValueError('Invalid elliptic curve point data length')
        else:
            raise ValueError('Unsupported elliptic curve point type') 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:ec.py

示例2: from_encoded_point

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def from_encoded_point(cls, curve, data):
        if not isinstance(curve, EllipticCurve):
            raise TypeError("curve must be an EllipticCurve instance")

        warnings.warn(
            "Support for unsafe construction of public numbers from "
            "encoded data will be removed in a future version. "
            "Please use EllipticCurvePublicKey.from_encoded_point",
            utils.DeprecatedIn25,
            stacklevel=2,
        )

        if data.startswith(b'\x04'):
            # key_size is in bits. Convert to bytes and round up
            byte_length = (curve.key_size + 7) // 8
            if len(data) == 2 * byte_length + 1:
                x = utils.int_from_bytes(data[1:byte_length + 1], 'big')
                y = utils.int_from_bytes(data[byte_length + 1:], 'big')
                return cls(x, y, curve)
            else:
                raise ValueError('Invalid elliptic curve point data length')
        else:
            raise ValueError('Unsupported elliptic curve point type') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:25,代码来源:ec.py

示例3: _load_ssh_ecdsa_public_key

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def _load_ssh_ecdsa_public_key(expected_key_type, decoded_data, backend):
    curve_name, rest = _read_next_string(decoded_data)
    data, rest = _read_next_string(rest)

    if expected_key_type != b"ecdsa-sha2-" + curve_name:
        raise ValueError(
            'Key header and key body contain different key type values.'
        )

    if rest:
        raise ValueError('Key body contains extra bytes.')

    curve = {
        b"nistp256": ec.SECP256R1,
        b"nistp384": ec.SECP384R1,
        b"nistp521": ec.SECP521R1,
    }[curve_name]()

    if six.indexbytes(data, 0) != 4:
        raise NotImplementedError(
            "Compressed elliptic curve points are not supported"
        )

    # key_size is in bits, and sometimes it's not evenly divisible by 8, so we
    # add 7 to round up the number of bytes.
    if len(data) != 1 + 2 * ((curve.key_size + 7) // 8):
        raise ValueError("Malformed key bytes")

    x = utils.int_from_bytes(
        data[1:1 + (curve.key_size + 7) // 8], byteorder='big'
    )
    y = utils.int_from_bytes(
        data[1 + (curve.key_size + 7) // 8:], byteorder='big'
    )
    return ec.EllipticCurvePublicNumbers(x, y, curve).public_key(backend) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:37,代码来源:serialization.py

示例4: _read_next_mpint

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def _read_next_mpint(data):
    """
    Reads the next mpint from the data.

    Currently, all mpints are interpreted as unsigned.
    """
    mpint_data, rest = _read_next_string(data)

    return (
        utils.int_from_bytes(mpint_data, byteorder='big', signed=False), rest
    ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:13,代码来源:serialization.py

示例5: from_encoded_point

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def from_encoded_point(cls, curve, data):
        if not isinstance(curve, EllipticCurve):
            raise TypeError("curve must be an EllipticCurve instance")

        if data.startswith(b'\x04'):
            # key_size is in bits. Convert to bytes and round up
            byte_length = (curve.key_size + 7) // 8
            if len(data) == 2 * byte_length + 1:
                x = utils.int_from_bytes(data[1:byte_length + 1], 'big')
                y = utils.int_from_bytes(data[byte_length + 1:], 'big')
                return cls(x, y, curve)
            else:
                raise ValueError('Invalid elliptic curve point data length')
        else:
            raise ValueError('Unsupported elliptic curve point type') 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:17,代码来源:ec.py

示例6: random_serial_number

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def random_serial_number():
    return utils.int_from_bytes(os.urandom(20), "big") >> 1 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:base.py

示例7: _ssh_read_next_mpint

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def _ssh_read_next_mpint(data):
    """
    Reads the next mpint from the data.

    Currently, all mpints are interpreted as unsigned.
    """
    mpint_data, rest = _ssh_read_next_string(data)

    return (
        utils.int_from_bytes(mpint_data, byteorder='big', signed=False), rest
    ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:serialization.py

示例8: as_integer

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def as_integer(self):
        if len(self.data) == 0:
            raise ValueError("Invalid DER input: empty integer contents")
        first = six.indexbytes(self.data, 0)
        if first & 0x80 == 0x80:
            raise ValueError("Negative DER integers are not supported")
        # The first 9 bits must not all be zero or all be ones. Otherwise, the
        # encoding should have been one byte shorter.
        if len(self.data) > 1:
            second = six.indexbytes(self.data, 1)
            if first == 0 and second & 0x80 == 0:
                raise ValueError(
                    "Invalid DER input: integer not minimally-encoded"
                )
        return int_from_bytes(self.data, "big") 
开发者ID:tp4a,项目名称:teleport,代码行数:17,代码来源:_der.py

示例9: verify

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def verify(self, message, signature):
        # First convert (r||s) raw signature to ASN1 encoded signature.
        sig_bytes = _helpers.to_bytes(signature)
        if len(sig_bytes) != 64:
            return False
        r = utils.int_from_bytes(sig_bytes[:32], byteorder="big")
        s = utils.int_from_bytes(sig_bytes[32:], byteorder="big")
        asn1_sig = encode_dss_signature(r, s)

        message = _helpers.to_bytes(message)
        try:
            self._pubkey.verify(asn1_sig, message, ec.ECDSA(hashes.SHA256()))
            return True
        except (ValueError, cryptography.exceptions.InvalidSignature):
            return False 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:17,代码来源:es256.py

示例10: getMP

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def getMP(data, count=1):
    """
    Get multiple precision integer out of the string.  A multiple precision
    integer is stored as a 4-byte length followed by length bytes of the
    integer.  If count is specified, get count integers out of the string.
    The return value is a tuple of count integers followed by the rest of
    the data.
    """
    mp = []
    c = 0
    for i in range(count):
        length, = struct.unpack('>L', data[c:c + 4])
        mp.append(int_from_bytes(data[c + 4:c + 4 + length], 'big'))
        c += 4 + length
    return tuple(mp) + (data[c:],) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:17,代码来源:common.py

示例11: _raw_to_der

# 需要导入模块: from cryptography import utils [as 别名]
# 或者: from cryptography.utils import int_from_bytes [as 别名]
def _raw_to_der(self, raw_signature):
        """Convert signature from RAW encoding to DER encoding."""
        component_length = self._sig_component_length()
        if len(raw_signature) != int(2 * component_length):
            raise ValueError("Invalid signature")

        r_bytes = raw_signature[:component_length]
        s_bytes = raw_signature[component_length:]
        r = int_from_bytes(r_bytes, "big")
        s = int_from_bytes(s_bytes, "big")
        return encode_dss_signature(r, s) 
开发者ID:mpdavis,项目名称:python-jose,代码行数:13,代码来源:cryptography_backend.py


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