当前位置: 首页>>代码示例>>Java>>正文


Java Security.addProvider方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:osswangxining,项目名称:iotgateway,代码行数:17,代码来源:CertPemClientCredentials.java

示例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());
}
 
开发者ID:xipki,项目名称:xitk,代码行数:9,代码来源:Providers.java

示例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);
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:10,代码来源:WolfCryptMessageDigestSha512Test.java

示例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;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:AddProvider.java

示例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());
}
 
开发者ID:pablopdomingos,项目名称:nfse,代码行数:38,代码来源:CertificadoConfig.java

示例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);
			
		}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:65,代码来源:TestJCAProvider.java

示例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());
	}
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:15,代码来源:RSA.java

示例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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TerminalFactorySpiTest.java

示例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());
    }
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:32,代码来源:SignUtils.java

示例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");

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:GetPrivateKey.java

示例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();

}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:26,代码来源:PaillierCryptosystemUtil.java

示例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);
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:14,代码来源:AESSensitivePropertyProvider.java

示例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());
  }
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:10,代码来源:EntryEncryptorTest.java

示例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();
}
 
开发者ID:oneops,项目名称:oneops,代码行数:20,代码来源:CmsCryptoDES.java


注:本文中的java.security.Security.addProvider方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。