/** * Generate a new AES 256 bit encryption key. Once generated, this key can * be used to replace the default key. * * @param keysize must be a supported key size, using 128 or 256 * @return */ public static String GEN(final short keysize) { try { return AesCbcWithIntegrity.generateKey().toString(); } catch (GeneralSecurityException ex) { log.log(Level.ERROR, "There was an error generating key, this could indicate that you're making a 256 bit key on a system that does not have the Java Crypto Extensions installed. . Is JCE installed? " + (isJCEInstalled ? "yes " : "no ") + ex.getMessage()); log.log(Level.DEBUG, "error generating key, this could indicate that you're making a 256 bit key on a system that does not have the Java Crypto Extensions installed. " + ex.getMessage(), ex); } return null; }
/** * Converts the given AES/HMAC keys into a base64 encoded string suitable for * storage. Sister function of keys. * * @param keys The combined aes and hmac keys * @return a base 64 encoded AES string & hmac key as base64(aesKey) : base64(hmacKey) */ public static String keyString(SecretKeys keys) { return keys.toString(); }