def __wrap_secret_key(plain_key, config):
        try:
            hash_algo = load_hash_algorithm(
                config.oaep_padding_digest_algorithm)
            _cipher = PKCS1_OAEP.new(key=RSA.import_key(
                config.encryption_certificate),
                                     hashAlgo=hash_algo)

            encrypted_secret_key = _cipher.encrypt(plain_key)
            return encode_bytes(encrypted_secret_key, config.data_encoding)

        except (IOError, TypeError):
            raise KeyWrappingError("Unable to encrypt session secret key.")
    def __unwrap_secret_key(encrypted_key, config, _hash):
        try:
            hash_algo = load_hash_algorithm(_hash)

            encrypted_key = decode_value(encrypted_key, config.data_encoding)
            _cipher = PKCS1_OAEP.new(key=config.decryption_key,
                                     hashAlgo=hash_algo)

            secret_key = _cipher.decrypt(encrypted_key)
            return secret_key

        except (IOError, TypeError, Error):
            raise KeyWrappingError("Unable to decrypt session secret key.")
Пример #3
0
    def test_load_hash_algorithm_dash(self):
        hash_algo = to_test.load_hash_algorithm("SHA-512")

        self.assertEqual(hash_algo, SHA512)
Пример #4
0
    def test_load_hash_algorithm_lowercase(self):
        hash_algo = to_test.load_hash_algorithm("sha384")

        self.assertEqual(hash_algo, SHA384)
Пример #5
0
    def test_load_hash_algorithm(self):
        hash_algo = to_test.load_hash_algorithm("SHA224")

        self.assertEqual(hash_algo, SHA224)