
com.github.agogs.securekey.util.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of securekey-maven-plugin Show documentation
Show all versions of securekey-maven-plugin Show documentation
This plugin is used to generate a AES key using sun.security.ssl.SecureKey which is then
Base64 encoded during build time and store it in the file system.
The "secret" to generate the key is passed as a parameter in the plugin configuration
The newest version!
package com.github.agogs.securekey.util;
import javax.crypto.SecretKey;
import java.util.Base64;
/**
* Expose utility methods
*
* @author agogs
*/
public class Util {
/**
* Encode a {@link SecretKey} object into base64 encoded string
* @param aesKey - Secret key
* @return - base64 encoded string
* @throws IllegalArgumentException
*/
public static String encodeAESKeyToBase64(final SecretKey aesKey)
throws IllegalArgumentException {
if (!aesKey.getAlgorithm().equalsIgnoreCase("AES")) {
throw new IllegalArgumentException("Not an AES key");
}
final byte[] keyData = aesKey.getEncoded();
final String encodedKey = Base64.getEncoder().encodeToString(keyData);
return encodedKey;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy