in src/dynamodb_encryption_sdk/internal/crypto/jce_bridge/encryption.py [0:0]
def from_transformation(cls, cipher_transformation):
"""Generates an JavaCipher object from the Java transformation.
https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html
https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Cipher
:param str cipher_transformation: Formatted transformation
:returns: JavaCipher instance
:rtype: JavaCipher
"""
if cipher_transformation == "AESWrap":
# AESWrap does not support encrypt or decrypt, so mode and padding are never
# used, but we use ECB and NoPadding as placeholders to simplify handling.
return cls.from_transformation("AESWrap/ECB/NoPadding")
if cipher_transformation == "RSA":
# RSA does not use mode, but as with JCE, we use ECB as a placeholder to simplify handling.
return cls.from_transformation("RSA/ECB/PKCS1Padding")
cipher_transformation_parts = cipher_transformation.split("/")
if len(cipher_transformation_parts) != 3:
raise JceTransformationError(
'Invalid transformation: "{}": must be three parts ALGORITHM/MODE/PADDING, "RSA", or "AESWrap"'.format(
cipher_transformation
)
)
cipher = cls._map_load_or_error("algorithm", cipher_transformation_parts[0], JAVA_ENCRYPTION_ALGORITHM)
mode = cls._map_load_or_error("mode", cipher_transformation_parts[1], JAVA_MODE)
padding = cls._map_load_or_error("padding", cipher_transformation_parts[2], JAVA_PADDING)
return cls(cipher, mode, padding)