
com.magictools.crypto.GlobalBouncyCastleProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magic-tools-all Show documentation
Show all versions of magic-tools-all Show documentation
magic-tools 是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
The newest version!
package com.magictools.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 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 - 2025 Weber Informatics LLC | Privacy Policy