Class Symmetric

java.lang.Object
convex.core.crypto.Symmetric

public class Symmetric extends Object
Class providing symmetric encryption functionality using AES
  • Constructor Details

    • Symmetric

      public Symmetric()
  • Method Details

    • encrypt

      public static byte[] encrypt(SecretKey key, String data)
      Encrypts a String with a given AES secret key, using standard UTF-8 encoding
      Parameters:
      key - AES secret key
      data - String to encrypt
      Returns:
      Encrypted representation of the given string
    • encrypt

      public static byte[] encrypt(SecretKey key, byte[] data)
      Encrypt bytes with a given AES SecretKey Prepends the IV to the ciphertext.
      Parameters:
      key - Secret encryption key
      data - Data to encrypt
      Returns:
      Encrypted representation of the given byte array data
    • decryptString

      public static String decryptString(SecretKey key, byte[] encryptedData)
      Decrypts a string from ciphertext, assuming UTF-8 format data
      Parameters:
      key - AES Secret Key
      encryptedData - encrypted byte[] data to decrypt (ciphertext)
      Returns:
      The decrypted String
    • decrypt

      public static byte[] decrypt(SecretKey key, byte[] encryptedData)
      Decrypts AES ciphertext with a given secret key. IV is assumed to be prepended to the cipherText
      Parameters:
      key - Secret encryption key
      encryptedData - Encrypted data to decrypt
      Returns:
      A new byte array containing the decrypted data
    • decrypt

      public static byte[] decrypt(SecretKey key, InputStream bis) throws IOException
      Decrypts AES ciphertext with a given secret key. IV is assumed to be prepended to the cipherText
      Parameters:
      key - Secret encryption key
      bis - InputStream of data to decrypt
      Returns:
      A new byte array containing the decrypted data
      Throws:
      IOException - If an IO error occurs
    • createSecretKey

      public static SecretKey createSecretKey()
      Creates an AES secret key
      Returns:
      The generated SecretKey