You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
890 B

5 days ago
package com.ruoyi.common.utils.security;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.KeyGenerator;
/**
*
*
* @author ruoyi
*/
public class CipherUtils
{
/**
*
*
* @param keyBitSize
* @param algorithmName
* @return
*/
public static Key generateNewKey(int keyBitSize, String algorithmName)
{
KeyGenerator kg;
try
{
kg = KeyGenerator.getInstance(algorithmName);
}
catch (NoSuchAlgorithmException e)
{
String msg = "Unable to acquire " + algorithmName + " algorithm. This is required to function.";
throw new IllegalStateException(msg, e);
}
kg.init(keyBitSize);
return kg.generateKey();
}
}