當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。