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


Java Security.getProvider方法代码示例

本文整理汇总了Java中java.security.Security.getProvider方法的典型用法代码示例。如果您正苦于以下问题:Java Security.getProvider方法的具体用法?Java Security.getProvider怎么用?Java Security.getProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.Security的用法示例。


在下文中一共展示了Security.getProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.security.Security; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");

    KeyGenerator kg;

    kg = KeyGenerator.getInstance("SunTlsRsaPremasterSecret", provider);

    try {
        kg.generateKey();
        throw new Exception("no exception");
    } catch (IllegalStateException e) {
        System.out.println("OK: " + e);
    }

    int[] protocolVersions = {0x0300, 0x0301, 0x0302, 0x0400};
    for (int clientVersion : protocolVersions) {
        for (int serverVersion : protocolVersions) {
            test(kg, clientVersion, serverVersion);
            if (serverVersion >= clientVersion) {
                break;
            }
        }
    }

    System.out.println("Done.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:TestPremaster.java

示例2: verifySignature

import java.security.Security; //导入方法依赖的package包/类
public static boolean verifySignature(CMSSignedData cmsSignedData, X509Certificate cert) {
    try {
        if (Security.getProvider("BC") == null)
            Security.addProvider(new BouncyCastleProvider());

        Collection<SignerInformation> signers = cmsSignedData.getSignerInfos().getSigners();
        X509CertificateHolder ch = new X509CertificateHolder(cert.getEncoded());
        for (SignerInformation si : signers)
            if (si.getSID().match(ch))
                if (si.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(ch)))
                    return true;
    } catch (Exception e) {}
    return false;
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:15,代码来源:PKCS7Manager.java

示例3: main

import java.security.Security; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Provider p = Security.getProvider("SunJCE");
    for (String alg : ALGORITHMS) {
        for (int keyStrength : KEY_STRENGTHS) {
            if (keyStrength > Cipher.getMaxAllowedKeyLength(alg)) {
                // skip this if this key length is larger than what's
                // configured in the JCE jurisdiction policy files
                continue;
            }
            for (int textLength : TEXT_LENGTHS) {
                for (int AADLength : AAD_LENGTHS) {
                    Encrypt test = new Encrypt(p, alg,
                            "GCM", "NoPadding", keyStrength, textLength,
                            AADLength);
                    Cipher cipher = test.createCipher(Cipher.ENCRYPT_MODE,
                            null);
                    AlgorithmParameters params = cipher.getParameters();
                    test.doTest(params);
                    System.out.println("Test " + alg + ":"
                            + keyStrength + ":" + textLength + ":"
                            + AADLength + " passed");
                }
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:Encrypt.java

示例4: testInvalidPrivateKey

import java.security.Security; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testInvalidPrivateKey() throws Exception {
    new ECKey(
        Security.getProvider("SunEC"),
        KeyPairGenerator.getInstance("RSA").generateKeyPair().getPrivate(),
        ECKey.fromPublicOnly(pubKey).getPubKeyPoint());
    fail("Expecting an IllegalArgumentException for using an non EC private key");
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:ECKeyTest.java

示例5: addProvider

import java.security.Security; //导入方法依赖的package包/类
/**
 * 添加签名,验签,加密算法提供者
 */
private static void addProvider(){
	if (Security.getProvider("BC") == null) {
		log.info("add BC provider");
		Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
	} else {
		Security.removeProvider("BC"); //解决eclipse调试时tomcat自动重新加载时,BC存在不明原因异常的问题。
		Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
		log.info("re-add BC provider");
	}
	printSysInfo();
}
 
开发者ID:howe,项目名称:nutz-pay,代码行数:15,代码来源:CertUtil.java

示例6: getProvider

import java.security.Security; //导入方法依赖的package包/类
static Provider getProvider(String provider)
    throws NoSuchProviderException
{
    Provider prov = Security.getProvider(provider);

    if (prov == null)
    {
        throw new NoSuchProviderException("Provider " + provider + " not found");
    }

    return prov;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:X509Util.java

示例7: publicToExplicitParameters

import java.security.Security; //导入方法依赖的package包/类
/**
 * Convert a passed in public EC key to have explicit parameters. If the key
 * is already using explicit parameters it is returned.
 *
 * @param key key to be converted
 * @param providerName provider name to be used.
 * @return the equivalent key with explicit curve parameters
 * @throws IllegalArgumentException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 */
public static PublicKey publicToExplicitParameters(PublicKey key, String providerName)
    throws IllegalArgumentException, NoSuchAlgorithmException, NoSuchProviderException
{
    Provider provider = Security.getProvider(providerName);

    if (provider == null)
    {
        throw new NoSuchProviderException("cannot find provider: " + providerName);
    }

    return publicToExplicitParameters(key, provider);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:ECKeyUtil.java

示例8: main

import java.security.Security; //导入方法依赖的package包/类
public static void main(String[] args) {
    PBESealedObject test = new PBESealedObject();
    Provider sunjce = Security.getProvider("SunJCE");

    if (!test.runAll(sunjce, System.out)) {
        throw new RuntimeException("One or more tests have failed....");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:PBESealedObject.java

示例9: 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,代码来源:WolfCryptSignatureTest.java

示例10: if

import java.security.Security; //导入方法依赖的package包/类
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Provider p = Security.getProvider(provider);
    if (p == null) {
        throw new NoSuchProviderException("No such provider: " +
                                          provider);
    }
    Service s = p.getService("TransformService", algorithm);
    if (s != null) {
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Object obj = s.newInstance(null);
            if (obj instanceof TransformService) {
                TransformService ts = (TransformService) obj;
                ts.algorithm = algorithm;
                ts.mechanism = mechanismType;
                ts.provider = p;
                return ts;
            }
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available from " + provider);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:TransformService.java

示例11: testSunECRoundTrip

import java.security.Security; //导入方法依赖的package包/类
@Test
public void testSunECRoundTrip() throws Exception {
    Provider provider = Security.getProvider("SunEC");
    if (provider != null) {
        testProviderRoundTrip(provider);
    } else {
        System.out.println("Skip test as provider doesn't exist. Must be OpenJDK 1.7 which ships without 'SunEC'");
    }
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:10,代码来源:ECKeyTest.java

示例12: 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

示例13: 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

示例14: main

import java.security.Security; //导入方法依赖的package包/类
public static void main(String[] args) {
    TestCipherPBECons test = new TestCipherPBECons();
    Provider sunjce = Security.getProvider("SunJCE");

    if (!test.runAll(sunjce, System.out)) {
        throw new RuntimeException("One or more tests have failed....");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestCipherPBECons.java

示例15: verifyAllSignatures

import java.security.Security; //导入方法依赖的package包/类
public static boolean verifyAllSignatures(CMSSignedData cmsSignedData) {
    try {
        if (Security.getProvider("BC") == null)
            Security.addProvider(new BouncyCastleProvider());

        Collection<SignerInformation> signers = cmsSignedData.getSignerInfos().getSigners();

        for (SignerInformation si : signers) {
            @SuppressWarnings("unchecked")
            Collection<X509CertificateHolder> certList = cmsSignedData.getCertificates().getMatches(si.getSID());
            if (certList.size() == 0)
                throw new Exception("ERROR: Impossible to find a Certificate using the Signer ID: " + si.getSID());

            X509CertificateHolder cert = certList.iterator().next(); // Take only the first certificate of the chain

            if (!si.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)))
                throw new Exception("ATTENTION: At least a signature is invalid!");

            boolean certOK = true;
            String msg = "";
            try {
                X509Utils.checkAllOnCertificate(X509Utils.getX509Certificate(cert.getEncoded()));
            } catch (Exception ex) {
                msg = ex.getMessage();
                certOK = false;
            }
            if (!certOK)
                throw new Exception("ATTENTION: The certificate is invalid:\n" + msg);
        }

        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:38,代码来源:PKCS7Manager.java


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