本文整理匯總了Java中java.security.Security.addProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java Security.addProvider方法的具體用法?Java Security.addProvider怎麽用?Java Security.addProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.Security
的用法示例。
在下文中一共展示了Security.addProvider方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSocketFactory
import java.security.Security; //導入方法依賴的package包/類
private SSLSocketFactory getSocketFactory() {
try {
Security.addProvider(new BouncyCastleProvider());
TrustManagerFactory trustManagerFactory = createAndInitTrustManagerFactory();
KeyManagerFactory keyManagerFactory = createAndInitKeyManagerFactory();
SSLContext context = SSLContext.getInstance(TLS_VERSION);
context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
return context.getSocketFactory();
} catch (Exception e) {
log.error("[{}:{}:{}:{}] Creating TLS factory failed!", caCert, cert, privateKey, password, e);
throw new RuntimeException("Creating TLS factory failed!", e);
}
}
示例2: addBcProvider
import java.security.Security; //導入方法依賴的package包/類
private void addBcProvider() {
final String provName = "BC";
if (Security.getProvider(provName) != null) {
LOG.info("security provider {} already initialized by other service", provName);
return;
}
Security.addProvider(new BouncyCastleProvider());
}
示例3: testProviderInstallationAtRuntime
import java.security.Security; //導入方法依賴的package包/類
@BeforeClass
public static void testProviderInstallationAtRuntime() {
/* install wolfJCE provider at runtime */
Security.addProvider(new WolfCryptProvider());
Provider p = Security.getProvider("wolfJCE");
assertNotNull(p);
}
示例4: main
import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
boolean legacy = args[0].equals("2");
Security.addProvider(new TestProvider("Test1"));
Security.insertProviderAt(new TestProvider("Test2"), 1);
try {
Security.addProvider(new TestProvider("Test3"));
if (legacy) {
throw new Exception("Expected SecurityException");
}
} catch (SecurityException se) {
if (!legacy) {
throw se;
}
}
}
示例5: carregarCertificados
import java.security.Security; //導入方法依賴的package包/類
@SuppressWarnings("restriction")
public void carregarCertificados() {
try {
this.getCertificadoKeyStore();
} catch (KeyStoreException e) {
e.printStackTrace();
}
System.clearProperty("javax.net.ssl.keyStore");
System.clearProperty("javax.net.ssl.keyStorePassword");
System.clearProperty("javax.net.ssl.trustStore");
if (this.getTipoCertificado().equals(TipoCertificado.A1)) {
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore", this.getCaminhoParaCertificado());
System.setProperty("javax.net.ssl.keyStorePassword", this.getSenhaCertificado());
} else if (this.getTipoCertificado().equals(TipoCertificado.A3_CARD)) {
System.setProperty("javax.net.ssl.keyStore", "NONE");
System.setProperty("javax.net.ssl.keyStoreType", "PKCS11");
System.setProperty("javax.net.ssl.keyStoreProvider", "SunPKCS11-SmartCard");
} else if (this.getTipoCertificado().equals(TipoCertificado.A3_TOKEN)) {
System.setProperty("javax.net.ssl.keyStore", "NONE");
System.setProperty("javax.net.ssl.keyStoreType", "PKCS11");
System.setProperty("javax.net.ssl.keyStoreProvider", "SunPKCS11-eToken");
}
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", this.getCaminhoParaCadeiaCertificado());
}
示例6: main
import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
TestJCAProvider d = new TestJCAProvider();
// Add dynamically the desired provider
Security.addProvider(new PaillierProvider());
/////////////////////////////////////////////////////////////////////
KeyPairGenerator kpg = KeyPairGenerator.getInstance("Paillier");
kpg.initialize(32);
KeyPair keyPair = kpg.generateKeyPair();
PublicKey pubKey = keyPair.getPublic();
PrivateKey privKey = keyPair.getPrivate();
final Cipher cipher = Cipher.getInstance("Paillier");
final Cipher cipherHP = Cipher.getInstance("PaillierHP");
System.out.println("The Paillier public key through Generator is \n"+keyPair.toString());
System.out.println("The Paillier public key is \n"+keyPair.getPublic().toString());
System.out.println("The Paillier private key is \n"+keyPair.getPrivate().toString());
String plainText = "101";
String plaintext1 = "101";
// get the n
String delims = "[,]";
String[] keyComponents = pubKey.toString().split(delims);
String keyComponent = "";
for (String keyComponent2 : keyComponents) {
if (keyComponent2.startsWith("n")) {
keyComponent = keyComponent2.substring(2);// ignoring 'n:' or 'r:'
}
}
BigInteger n = new BigInteger(keyComponent);
BigInteger first = new BigInteger(plainText);
BigInteger second = new BigInteger(plaintext1);
BigInteger n2 = n.multiply(n);
// encrypt
BigInteger codedBytes = d.encrypt(first.toByteArray(), pubKey,cipherHP);
BigInteger codedBytes12 = d.encrypt(second.toByteArray(), pubKey,cipherHP);
//product
BigInteger product = codedBytes.multiply(codedBytes12);
// product mod n^2
BigInteger tallyProduct = product.mod(n2);
System.out.println(" Product mod n^2: "+tallyProduct);
d.decrypt(tallyProduct.toByteArray(), privKey,cipherHP);
d.decrypt(codedBytes.toByteArray(),privKey,cipherHP);
d.decrypt(codedBytes12.toByteArray(),privKey,cipherHP);
//////////////////////////////BLOCK EXAMPLE/////////////////////////////////
String plainTextBlock = "This Provider working correctly and its safe 10000000000000000011000000000000000001";
System.out.println("This is the message which will be encrypted: " + plainTextBlock);
// encrypt
byte[] codedBytesBlock = d.encryptBlock(plainTextBlock.getBytes(), pubKey,cipher);
String codedMessageBlock = new String(codedBytesBlock);
String codedMessageBlockInHEX = formatingHexRepresentation(codedBytesBlock);
System.out.println("\n" + "ENCRYPTED : \n" + codedMessageBlock);
System.out.println("\n" + "ENCRYPTED in HEX: \n" + codedMessageBlockInHEX);
// decrypt
byte[] encodedBytesBlock = d.decryptBlock(codedMessageBlock, privKey,cipher);
String encodedMessageBlock = new String(encodedBytesBlock);
System.out.println("\n" + "DECRYPTED: \n" + encodedMessageBlock);
}
示例7: init
import java.security.Security; //導入方法依賴的package包/類
private static void init() {
try {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
cipher = Cipher.getInstance(INSTANCE_TYPE);
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "BC");
generator.initialize(1024);
KeyPair pair = generator.generateKeyPair();
PUBLIC_KEY = org.apache.commons.codec.binary.Base64.encodeBase64String(pair.getPublic().getEncoded());
privKey = pair.getPrivate();
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException e) {
e.printStackTrace();
Log.e(e.getMessage());
}
}
示例8: main
import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Provider myProvider = new MyProvider();
Security.addProvider(myProvider);
System.out.println(Arrays.asList(Security.getProviders()));
TerminalFactory.getInstance("MyType", new Object()).terminals();
if (!callMethod) {
throw new RuntimeException("Expected engineTerminals() not called");
}
}
示例9: calculateHASH
import java.security.Security; //導入方法依賴的package包/類
public static byte[] calculateHASH(String digestOID, byte[] data) throws Exception{
String digestName = "";
try{
if(Security.getProvider("BC") == null)
Security.addProvider(new BouncyCastleProvider());
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_MD5))
digestName = "MD5";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA1))
digestName = "SHA-1";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA256))
digestName = "SHA-256";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA384))
digestName = "SHA-384";
if(digestOID.equals(CMSSignedDataGenerator.DIGEST_SHA512))
digestName = "SHA-512";
if(digestName.equals(""))
throw new Exception("Unsupported digestOID");
MessageDigest md = MessageDigest.getInstance(digestName, "BC");
md.update(data);
byte[] hash = md.digest();
return hash;
}catch(Exception e){
throw new Exception("Error on the generation for the Hash "+digestName+":\n"+e.getMessage());
}
}
示例10: main
import java.security.Security; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
if (initSecmod() == false) {
return;
}
String configName = BASE + SEP + "nss.cfg";
Provider p = getSunPKCS11(configName);
System.out.println(p);
Security.addProvider(p);
if (args.length > 1 && "sm".equals(args[0])) {
System.setProperty("java.security.policy",
BASE + File.separator + args[1]);
System.setSecurityManager(new SecurityManager());
}
KeyStore ks = KeyStore.getInstance(PKCS11, p);
ks.load(null, password);
Collection<String> aliases = new TreeSet<>(
Collections.list(ks.aliases()));
System.out.println("entries: " + aliases.size());
System.out.println(aliases);
PrivateKey privateKey = (PrivateKey)ks.getKey(keyAlias, password);
System.out.println(privateKey);
byte[] data = generateData(1024);
System.out.println("Signing...");
Signature signature = Signature.getInstance("MD5withRSA");
signature.initSign(privateKey);
signature.update(data);
byte[] sig = signature.sign();
X509Certificate[] chain =
(X509Certificate[]) ks.getCertificateChain(keyAlias);
signature.initVerify(chain[0].getPublicKey());
signature.update(data);
boolean ok = signature.verify(sig);
if (ok == false) {
throw new Exception("Signature verification error");
}
System.out.println("OK");
}
示例11: PaillierCryptosystemUtil
import java.security.Security; //導入方法依賴的package包/類
/**
* The constructor PaillierCryptosystemUtil is responsible for adding the
* Paillier Provider, initialise the key size and generate public and
* private keys. This is done once only here with the clear idea to be used
* the same keys for all encryption and decryption operations within the
* class. The instance of PaillierCryptosystemUtil is made just once from
* the main class, this way we assure that the homomorphic properties of
* Paillier Cryptosystem will be in use.
*
* @throws NoSuchAlgorithmException
*
*/
PaillierCryptosystemUtil() throws NoSuchAlgorithmException {
// Add dynamically the desired provider
Security.addProvider(new PaillierProvider());
// generates pairs of public and private keys
KeyPairGenerator kpg = KeyPairGenerator.getInstance("Paillier");
// Initialise key size in bits
kpg.initialize(32);// 8 bits = 1 byte
KeyPair keyPair = kpg.generateKeyPair();
pubKey = keyPair.getPublic();
privKey = keyPair.getPrivate();
}
示例12: createSocketFactory
import java.security.Security; //導入方法依賴的package包/類
public static SSLSocketFactory createSocketFactory(
final String caCertificateFileName,
final String clientCertificateFileName,
final String clientKeyFileName) throws Exception
{
// Creates a TLS socket factory with the given
// CA certificate file, client certificate, client key
// In this case, we are working without a client key password
final String clientKeyPassword = "";
try
{
Security.addProvider(new BouncyCastleProvider());
final KeyManager[] keyManagers = createKeyManagerFactory(clientCertificateFileName, clientKeyFileName, clientKeyPassword).getKeyManagers();
final TrustManager[] trustManagers = createTrustManagerFactory(caCertificateFileName).getTrustManagers();
// Create the TLS socket factory for the desired TLS version
final SSLContext context = SSLContext.getInstance(TLS_VERSION);
context.init(keyManagers, trustManagers, new SecureRandom());
//context.init(keyManagers, trustManagers, null);
return context.getSocketFactory();
}
catch (Exception e)
{
throw new Exception("I cannot create the TLS socket factory.", e);
}
}
開發者ID:PacktPublishing,項目名稱:MQTT-Essentials-A-Lightweight-IoT-Protocol,代碼行數:29,代碼來源:SecurityHelper.java
示例13: AESSensitivePropertyProvider
import java.security.Security; //導入方法依賴的package包/類
public AESSensitivePropertyProvider(String keyHex) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException {
byte[] key = validateKey(keyHex);
try {
Security.addProvider(new BouncyCastleProvider());
cipher = Cipher.getInstance(ALGORITHM, PROVIDER);
// Only store the key if the cipher was initialized successfully
this.key = new SecretKeySpec(key, "AES");
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException e) {
logger.error("Encountered an error initializing the {}: {}", IMPLEMENTATION_NAME, e.getMessage());
throw new SensitivePropertyProtectionException("Error initializing the protection cipher", e);
}
}
示例14: setup
import java.security.Security; //導入方法依賴的package包/類
/**
* Ensure that BouncyCastleProvider is registered.
*/
@BeforeClass
public static void setup() {
if (Security.getProvider("BC") == null) {
Security.addProvider(new BouncyCastleProvider());
}
}
示例15: init
import java.security.Security; //導入方法依賴的package包/類
/**
* Inits the.
*
* @throws java.io.IOException Signals that an I/O exception has occurred.
* @throws java.security.GeneralSecurityException the general security exception
*/
public void init() throws IOException, GeneralSecurityException {
Security.addProvider(new BouncyCastleProvider());
this.secretKeyFile = System.getenv("CMS_DES_PEM");
if (this.secretKeyFile == null) {
this.secretKeyFile = System.getProperty("com.kloopz.crypto.cms_des_pem");
}
if (this.secretKeyFile == null) {
logger.error(">>>>>>>>>>>>>>Failed to init DES Encryptor/Decryptor no key faile is set, use CMS_DES_PEM env var to set location!");
throw new FileNotFoundException("Failed to init DES Encryptor/Decryptor no key faile is set, use CMS_DES_PEM env var to set location!");
}
initEncryptorDecryptor();
}