Package com.seeq.utilities.encryption
Class SimpleHybrid
java.lang.Object
com.seeq.utilities.encryption.SimpleHybrid
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Decrypt the "key.enc" file within the input directory usingSimpleRSA.decrypt(PrivateKey, byte[])
.static void
Encrypt the input file usingSimpleAES.encrypt(File, File)
and store the result in "data.enc" within the output directory.
-
Method Details
-
encrypt
public static void encrypt(File publicKeyFile, File inputFile, File outputDir) throws IOException, InvalidKeyException, InvalidKeySpecException Encrypt the input file usingSimpleAES.encrypt(File, File)
and store the result in "data.enc" within the output directory. Then encrypt the AES secret key usingSimpleRSA.encrypt(PublicKey, byte[])
and store the result in "key.enc" within the output directory.- Parameters:
publicKeyFile
- a DER encoded X509 public key fileinputFile
- a file containing the data to be encryptedoutputDir
- the directory to write the encrypted data and key files- Throws:
IOException
- if an error occurs while reading the public key or input files or writing the output filesInvalidKeyException
- if the public key is not validInvalidKeySpecException
- if the public key file does not contain a valid public key in X509 format
-
decrypt
public static void decrypt(File privateKeyFile, File inputDir, File outputFile) throws IOException, InvalidKeyException, InvalidKeySpecException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException Decrypt the "key.enc" file within the input directory usingSimpleRSA.decrypt(PrivateKey, byte[])
. Use the result as the secret key to decrypt the "data.enc" file within the input directory usingSimpleAES.decrypt(byte[], File, File)
and store the result in the output file.- Parameters:
privateKeyFile
- a DER encoded PKCS8 private key fileinputDir
- a directory containing the encrypted data and key filesoutputFile
- the file to write the decrypted data to- Throws:
IOException
- if an error occurs while reading the private key or input files or writing the output fileInvalidKeyException
- if the private key is not valid or if the decrypted secret key is not validInvalidKeySpecException
- if the private key file does not contain a valid private key in PKCS8 formatBadPaddingException
- if the encrypted key does not have OAEPWithSHA-256AndMGF1 paddingIllegalBlockSizeException
- if the encrypted key cannot be processedInvalidAlgorithmParameterException
- if the initialization vector at the beginning of "data.enc" is invalid
-