devutility.internal.security.AesUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Some utilities for Java development
package devutility.internal.security;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
/**
*
* AesUtils
*
* @author: Aldwin Su
* @version: 2019-08-07 15:16:23
*/
public class AesUtils {
public SecretKey secretKey(String key, int keySize) throws NoSuchAlgorithmException {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(keySize, new SecureRandom(key.getBytes()));
return keyGenerator.generateKey();
}
public SecretKey secretKey(String key) throws NoSuchAlgorithmException {
return secretKey(key, 128);
}
}