Package com.dracoon.sdk.crypto
Class Crypto
java.lang.Object
com.dracoon.sdk.crypto.Crypto
This class is the main class of the Dracoon Crypto Library.
The class provides methods for:
- User key pair generation:
- User key pair check:
- File key generation:
- File key encryption:
- File key decryption:
- Cipher creation for file encryption:
- Cipher creation for file decryption:
The class provides methods for:
- User key pair generation:
generateUserKeyPair- User key pair check:
checkUserKeyPair- File key generation:
generateFileKey- File key encryption:
encryptFileKey- File key decryption:
decryptFileKey- Cipher creation for file encryption:
createFileEncryptionCipher- Cipher creation for file decryption:
createFileDecryptionCipher-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckUserKeyPair(UserKeyPair userKeyPair, char[] password) Checks if a user key pair can be unlocked.static FileDecryptionCiphercreateFileDecryptionCipher(PlainFileKey fileKey) Creates a file decryption cipher.static FileEncryptionCiphercreateFileEncryptionCipher(PlainFileKey fileKey) Creates a file encryption cipher.static PlainFileKeydecryptFileKey(EncryptedFileKey encFileKey, UserPrivateKey userPrivateKey, char[] password) Decrypts a file key.static EncryptedFileKeyencryptFileKey(PlainFileKey plainFileKey, UserPublicKey userPublicKey) Encrypts a file key.static PlainFileKeygenerateFileKey(PlainFileKey.Version version) Generates a random file key.
IMPORTANT!!!: Never reuse the returned file key! Use the returned file key only for the encryption of one file!
The file key consists of a cryptographic key and initialization vector.static UserKeyPairgenerateUserKeyPair(UserKeyPair.Version version, char[] password) Generates a random user key pair.
-
Method Details
-
generateUserKeyPair
public static UserKeyPair generateUserKeyPair(UserKeyPair.Version version, char[] password) throws IllegalArgumentException, InvalidKeyPairException, InvalidPasswordException, CryptoSystemException Generates a random user key pair.- Parameters:
version- The version for which the key pair should be created.password- The password which should be used to secure the private key.- Returns:
- The generated user key pair.
- Throws:
IllegalArgumentException- If a parameter is invalid (e.g. null).InvalidKeyPairException- If the version for the user key pair is not supported.InvalidPasswordException- If the password to secure the private key is invalid.CryptoSystemException- If a unknown error occurred.
-
checkUserKeyPair
public static boolean checkUserKeyPair(UserKeyPair userKeyPair, char[] password) throws InvalidKeyPairException, CryptoSystemException Checks if a user key pair can be unlocked.- Parameters:
userKeyPair- The user key pair which should be unlocked.password- The password which secures the private key.- Returns:
- True if the user key pair could be unlocked. Otherwise false.
- Throws:
IllegalArgumentException- If a parameter is invalid (e.g. null).InvalidKeyPairException- If the user key pair is invalid.CryptoSystemException- If a unknown error occurred.
-
encryptFileKey
public static EncryptedFileKey encryptFileKey(PlainFileKey plainFileKey, UserPublicKey userPublicKey) throws InvalidFileKeyException, InvalidKeyPairException, CryptoSystemException Encrypts a file key.- Parameters:
plainFileKey- The file key to encrypt.userPublicKey- The public key which should be used at the encryption.- Returns:
- The encrypted file key.
- Throws:
IllegalArgumentException- If a parameter is invalid (e.g. null).InvalidFileKeyException- If the provided plain file key is invalid.InvalidKeyPairException- If the provided public key is invalid.CryptoSystemException- If a unknown error occurred.
-
decryptFileKey
public static PlainFileKey decryptFileKey(EncryptedFileKey encFileKey, UserPrivateKey userPrivateKey, char[] password) throws InvalidFileKeyException, InvalidKeyPairException, InvalidPasswordException, CryptoSystemException Decrypts a file key.- Parameters:
encFileKey- The file key to decrypt.userPrivateKey- The private key which should be used at the decryption.password- The password which secures the private key.- Returns:
- The decrypted file key.
- Throws:
IllegalArgumentException- If a parameter is invalid (e.g. null).InvalidFileKeyException- If the provided encrypted file key is invalid.InvalidKeyPairException- If the provided private key is invalid.InvalidPasswordException- If the provided private key password is invalid.CryptoSystemException- If a unknown error occurred.
-
generateFileKey
Generates a random file key.
IMPORTANT!!!: Never reuse the returned file key! Use the returned file key only for the encryption of one file!
The file key consists of a cryptographic key and initialization vector. If you reuse both, you compromise the privacy of the encrypted file!- Parameters:
version- The encryption version for which the file key should be created.- Returns:
- The generated file key.
- Throws:
IllegalArgumentException- If a parameter is invalid (e.g. null).
-
createFileEncryptionCipher
public static FileEncryptionCipher createFileEncryptionCipher(PlainFileKey fileKey) throws CryptoSystemException Creates a file encryption cipher.- Parameters:
fileKey- The file key which should be used at the encryption.- Returns:
- The file encryption cipher.
- Throws:
IllegalArgumentException- If a parameter is invalid (e.g. null).CryptoSystemException- If a unknown error occurred.
-
createFileDecryptionCipher
public static FileDecryptionCipher createFileDecryptionCipher(PlainFileKey fileKey) throws CryptoSystemException Creates a file decryption cipher.- Parameters:
fileKey- The file key which should be used at the decryption.- Returns:
- The file decryption cipher.
- Throws:
IllegalArgumentException- If a parameter is invalid (e.g. null).CryptoSystemException- If a unknown error occurred.
-