Class SimpleHybrid

java.lang.Object
com.seeq.utilities.encryption.SimpleHybrid

public final class SimpleHybrid extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    decrypt(File privateKeyFile, File inputDir, File outputFile)
    Decrypt the "key.enc" file within the input directory using SimpleRSA.decrypt(PrivateKey, byte[]).
    static void
    encrypt(File publicKeyFile, File inputFile, File outputDir)
    Encrypt the input file using SimpleAES.encrypt(File, File) and store the result in "data.enc" within the output directory.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • encrypt

      public static void encrypt(File publicKeyFile, File inputFile, File outputDir) throws IOException, InvalidKeyException, InvalidKeySpecException
      Encrypt the input file using SimpleAES.encrypt(File, File) and store the result in "data.enc" within the output directory. Then encrypt the AES secret key using SimpleRSA.encrypt(PublicKey, byte[]) and store the result in "key.enc" within the output directory.
      Parameters:
      publicKeyFile - a DER encoded X509 public key file
      inputFile - a file containing the data to be encrypted
      outputDir - 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 files
      InvalidKeyException - if the public key is not valid
      InvalidKeySpecException - if the public key file does not contain a valid public key in X509 format
    • decrypt

      Decrypt the "key.enc" file within the input directory using SimpleRSA.decrypt(PrivateKey, byte[]). Use the result as the secret key to decrypt the "data.enc" file within the input directory using SimpleAES.decrypt(byte[], File, File) and store the result in the output file.
      Parameters:
      privateKeyFile - a DER encoded PKCS8 private key file
      inputDir - a directory containing the encrypted data and key files
      outputFile - 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 file
      InvalidKeyException - if the private key is not valid or if the decrypted secret key is not valid
      InvalidKeySpecException - if the private key file does not contain a valid private key in PKCS8 format
      BadPaddingException - if the encrypted key does not have OAEPWithSHA-256AndMGF1 padding
      IllegalBlockSizeException - if the encrypted key cannot be processed
      InvalidAlgorithmParameterException - if the initialization vector at the beginning of "data.enc" is invalid