Enum class Cipher
Package: keychain.constants
Description
Symmetric cipher.
Use cipher to specify the specific symmetric cipher algorithm and parameters a persona should use during encrypting the cleartext portion (producing ciphertext) and/or the asymmetric private key portion (producing a key lock) in hybrid encryption.
Since: v2.0
Enum Class Summary
Enum Constant | Value | Description |
---|---|---|
1 |
Advanced Encryption Standard block cipher in Galois Counter Mode with 128-bit block size |
|
2 |
Advanced Encryption Standard block cipher in Galois Counter Mode with 192-bit block size |
|
3 |
Advanced Encryption Standard block cipher in Galois Counter Mode with 256-bit block size |
|
4 |
Camelia block cipher in Galois Counter Mode with 128-bit block size |
|
5 |
Camelia block cipher in Galois Counter Mode with 192-bit block size |
|
6 |
Camelia block cipher in Galois Counter Mode with 256-bit block size |
Enum Class Detail
AES Ciphers
AES_GCM_128
Value: 1
Advanced Encryption Standard block cipher in Galois Counter Mode with 128-bit block size. AES-GCM provides both confidentiality and authenticity in a single operation, making it ideal for secure communications.
Camelia Ciphers
CAMELLIA_GCM_128
Value: 4
Camelia block cipher in Galois Counter Mode with 128-bit block size. Provides similar security properties to AES-GCM-128 with an alternative algorithm.
Usage Example
from keychain.constants import Cipher, CipherClass
# Select a specific cipher
cipher = Cipher.AES_GCM_256
print(f"Selected cipher: {cipher}") # Outputs: 3
# Choose cipher based on security requirements
def select_cipher(security_level="medium", algorithm_preference="aes"):
if algorithm_preference.lower() == "aes":
if security_level == "low":
return Cipher.AES_GCM_128
elif security_level == "medium":
return Cipher.AES_GCM_192
else: # high security
return Cipher.AES_GCM_256
else: # camelia
if security_level == "low":
return Cipher.CAMELLIA_GCM_128
elif security_level == "medium":
return Cipher.CAMELLIA_GCM_192
else: # high security
return Cipher.CAMELLIA_GCM_256
recommended_cipher = select_cipher("high", "aes")
print(f"Recommended cipher: {recommended_cipher}")
# Get cipher properties
def get_cipher_properties(cipher):
properties = {
"key_size": None,
"algorithm": None,
"mode": "GCM",
"authenticated": True
}
name = cipher.name
if "128" in name:
properties["key_size"] = 128
elif "192" in name:
properties["key_size"] = 192
elif "256" in name:
properties["key_size"] = 256
if "AES" in name:
properties["algorithm"] = "AES"
elif "CAMELLIA" in name:
properties["algorithm"] = "Camellia"
return properties
props = get_cipher_properties(cipher)
print(f"Cipher properties: {props}")
# Get cipher class from cipher
def get_cipher_class(cipher):
if "AES" in cipher.name:
return CipherClass.AES
elif "CAMELLIA" in cipher.name:
return CipherClass.CAMELIA
return None
cipher_class = get_cipher_class(cipher)
print(f"Cipher class: {cipher_class}")
# Check if cipher supports authenticated encryption
def is_authenticated_encryption(cipher):
# All GCM mode ciphers provide authenticated encryption
return "GCM" in cipher.name
auth_encryption = is_authenticated_encryption(cipher)
print(f"Provides authenticated encryption: {auth_encryption}")