Search in sources :

Example 1 with BaseWeGooException

use of com.github.zhenwei.core.exception.BaseWeGooException in project LinLong-Java by zhenwei1108.

the class KeyBuilder method buildKey.

/**
 * @param [keyEnum]
 * @return java.security.Key
 * @author zhangzhenwei
 * @description 生成对称密钥
 * @date 2022/2/11 22:34
 * @since 1.0
 */
public Key buildKey(KeyEnum keyEnum) throws BaseWeGooException {
    try {
        val generator = KeyGenerator.getInstance(keyEnum.getAlg(), provider);
        generator.init(keyEnum.getKeyLen(), new SecureRandom());
        return generator.generateKey();
    } catch (Exception e) {
        throw new WeGooKeyException(KeyExceptionMessageEnum.generate_key_err, e);
    }
}
Also used : lombok.val(lombok.val) WeGooKeyException(com.github.zhenwei.core.exception.WeGooKeyException) WeGooCryptoException(com.github.zhenwei.core.exception.WeGooCryptoException) WeGooKeyException(com.github.zhenwei.core.exception.WeGooKeyException) BaseWeGooException(com.github.zhenwei.core.exception.BaseWeGooException)

Aggregations

BaseWeGooException (com.github.zhenwei.core.exception.BaseWeGooException)1 WeGooCryptoException (com.github.zhenwei.core.exception.WeGooCryptoException)1 WeGooKeyException (com.github.zhenwei.core.exception.WeGooKeyException)1 lombok.val (lombok.val)1