cn.hutool.crypto.GlobalBouncyCastleProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.crypto;
import java.security.Provider;
/**
* 全局单例的 org.bouncycastle.jce.provider.BouncyCastleProvider 对象
*
* @author looly
*/
public enum GlobalBouncyCastleProvider {
/**
* 单例
*/
INSTANCE;
private Provider provider;
private static boolean useBouncyCastle = true;
GlobalBouncyCastleProvider() {
try {
this.provider = ProviderFactory.createBouncyCastleProvider();
} catch (NoClassDefFoundError | NoSuchMethodError e) {
// ignore
}
}
/**
* 获取{@link Provider}
*
* @return {@link Provider}
*/
public Provider getProvider() {
return useBouncyCastle ? this.provider : null;
}
/**
* 设置是否使用Bouncy Castle库
* 如果设置为false,表示强制关闭Bouncy Castle而使用JDK
*
* @param isUseBouncyCastle 是否使用BouncyCastle库
* @since 4.5.2
*/
public static void setUseBouncyCastle(boolean isUseBouncyCastle) {
useBouncyCastle = isUseBouncyCastle;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy