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


Python primitives.serialization方法代码示例

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


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

示例1: parameter_bytes

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def parameter_bytes(self, encoding, format):
        if format is not serialization.ParameterFormat.PKCS3:
            raise ValueError(
                "Only PKCS3 serialization is supported"
            )
        if not self._backend._lib.Cryptography_HAS_EVP_PKEY_DHX:
            q = self._backend._ffi.new("BIGNUM **")
            self._backend._lib.DH_get0_pqg(self._dh_cdata,
                                           self._backend._ffi.NULL,
                                           q,
                                           self._backend._ffi.NULL)
            if q[0] != self._backend._ffi.NULL:
                raise UnsupportedAlgorithm(
                    "DH X9.42 serialization is not supported",
                    _Reasons.UNSUPPORTED_SERIALIZATION)

        return self._backend._parameter_bytes(
            encoding,
            format,
            self._dh_cdata
        ) 
开发者ID:tp4a,项目名称:teleport,代码行数:23,代码来源:dh.py

示例2: private_bytes

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def private_bytes(self, encoding, format, encryption_algorithm):
        if format is not serialization.PrivateFormat.PKCS8:
            raise ValueError(
                "DH private keys support only PKCS8 serialization"
            )
        if not self._backend._lib.Cryptography_HAS_EVP_PKEY_DHX:
            q = self._backend._ffi.new("BIGNUM **")
            self._backend._lib.DH_get0_pqg(self._dh_cdata,
                                           self._backend._ffi.NULL,
                                           q,
                                           self._backend._ffi.NULL)
            if q[0] != self._backend._ffi.NULL:
                raise UnsupportedAlgorithm(
                    "DH X9.42 serialization is not supported",
                    _Reasons.UNSUPPORTED_SERIALIZATION)

        return self._backend._private_key_bytes(
            encoding,
            format,
            encryption_algorithm,
            self._evp_pkey,
            self._dh_cdata
        ) 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:dh.py

示例3: public_bytes

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def public_bytes(self, encoding, format):
        if format is not serialization.PublicFormat.SubjectPublicKeyInfo:
            raise ValueError(
                "DH public keys support only "
                "SubjectPublicKeyInfo serialization"
            )

        if not self._backend._lib.Cryptography_HAS_EVP_PKEY_DHX:
            q = self._backend._ffi.new("BIGNUM **")
            self._backend._lib.DH_get0_pqg(self._dh_cdata,
                                           self._backend._ffi.NULL,
                                           q,
                                           self._backend._ffi.NULL)
            if q[0] != self._backend._ffi.NULL:
                raise UnsupportedAlgorithm(
                    "DH X9.42 serialization is not supported",
                    _Reasons.UNSUPPORTED_SERIALIZATION)

        return self._backend._public_key_bytes(
            encoding,
            format,
            self,
            self._evp_pkey,
            None
        ) 
开发者ID:tp4a,项目名称:teleport,代码行数:27,代码来源:dh.py

示例4: _encode_point

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def _encode_point(self, format):
        if format is serialization.PublicFormat.CompressedPoint:
            conversion = self._backend._lib.POINT_CONVERSION_COMPRESSED
        else:
            assert format is serialization.PublicFormat.UncompressedPoint
            conversion = self._backend._lib.POINT_CONVERSION_UNCOMPRESSED

        group = self._backend._lib.EC_KEY_get0_group(self._ec_key)
        self._backend.openssl_assert(group != self._backend._ffi.NULL)
        point = self._backend._lib.EC_KEY_get0_public_key(self._ec_key)
        self._backend.openssl_assert(point != self._backend._ffi.NULL)
        with self._backend._tmp_bn_ctx() as bn_ctx:
            buflen = self._backend._lib.EC_POINT_point2oct(
                group, point, conversion, self._backend._ffi.NULL, 0, bn_ctx
            )
            self._backend.openssl_assert(buflen > 0)
            buf = self._backend._ffi.new("char[]", buflen)
            res = self._backend._lib.EC_POINT_point2oct(
                group, point, conversion, buf, buflen, bn_ctx
            )
            self._backend.openssl_assert(buflen == res)

        return self._backend._ffi.buffer(buf)[:] 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:ec.py

示例5: test_decrypt_key

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def test_decrypt_key(self, mock_load_pem_private_key,
                         mock_default_backend, mock_no_encryption_class):
        mock_private_key = mock.MagicMock()
        mock_load_pem_private_key.return_value = mock_private_key
        mock_private_key.private_bytes.return_value = mock.sentinel.decrypted

        actual_decrypted = operations.decrypt_key(mock.sentinel.key,
                                                  mock.sentinel.passphrase)

        mock_load_pem_private_key.assert_called_once_with(
            mock.sentinel.key, mock.sentinel.passphrase)
        mock_private_key.private_bytes.assert_called_once_with(
            encoding=serialization.Encoding.PEM,
            format=serialization.PrivateFormat.PKCS8,
            encryption_algorithm=mock_no_encryption_class.return_value
        )
        self.assertEqual(mock.sentinel.decrypted, actual_decrypted) 
开发者ID:openstack,项目名称:magnum,代码行数:19,代码来源:test_operations.py

示例6: public_bytes

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def public_bytes(self, encoding, format):
        if format is serialization.PublicFormat.PKCS1:
            raise ValueError(
                "DSA public keys do not support PKCS1 serialization"
            )

        return self._backend._public_key_bytes(
            encoding,
            format,
            self._evp_pkey,
            None
        ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:14,代码来源:dsa.py

示例7: public_bytes

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def public_bytes(self, encoding, format):
        if format is serialization.PublicFormat.PKCS1:
            raise ValueError(
                "EC public keys do not support PKCS1 serialization"
            )

        return self._backend._public_key_bytes(
            encoding,
            format,
            self._evp_pkey,
            None
        ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:14,代码来源:ec.py

示例8: public_bytes

# 需要导入模块: from cryptography.hazmat import primitives [as 别名]
# 或者: from cryptography.hazmat.primitives import serialization [as 别名]
def public_bytes(self, encoding, format):
        if format is serialization.PublicFormat.PKCS1:
            raise ValueError(
                "DSA public keys do not support PKCS1 serialization"
            )

        return self._backend._public_key_bytes(
            encoding,
            format,
            self,
            self._evp_pkey,
            None
        ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:dsa.py


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