當前位置: 首頁>>代碼示例>>Java>>正文


Java Provider類代碼示例

本文整理匯總了Java中java.security.Provider的典型用法代碼示例。如果您正苦於以下問題:Java Provider類的具體用法?Java Provider怎麽用?Java Provider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Provider類屬於java.security包,在下文中一共展示了Provider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: installSecureRandomProvider

import java.security.Provider; //導入依賴的package包/類
private void installSecureRandomProvider(Provider provider) {
	Provider[] providers = Security.getProviders("SecureRandom.SHA1PRNG");
	if (providers == null || providers.length == 0
			|| !provider.getClass().equals(providers[0].getClass())) {
		Security.insertProviderAt(provider, 1);
	}
	// Check the new provider is the default when no algorithm is specified
	SecureRandom random = new SecureRandom();
	if (!provider.getClass().equals(random.getProvider().getClass())) {
		throw new SecurityException("Wrong SecureRandom provider: "
				+ random.getProvider().getClass());
	}
	// Check the new provider is the default when SHA1PRNG is specified
	try {
		random = SecureRandom.getInstance("SHA1PRNG");
	} catch (NoSuchAlgorithmException e) {
		throw new SecurityException(e);
	}
	if (!provider.getClass().equals(random.getProvider().getClass())) {
		throw new SecurityException("Wrong SHA1PRNG provider: "
				+ random.getProvider().getClass());
	}
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:24,代碼來源:CryptoComponentImpl.java

示例2: main

import java.security.Provider; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SunJCE");
    if (provider == null) {
        throw new RuntimeException("SunJCE provider not exist");
    }
    // generate no-padding cipher with secret key
    Cipher c = Cipher.getInstance("DES/CBC/NoPadding", provider);
    KeyGenerator kgen = KeyGenerator.getInstance("DES", provider);
    SecretKey skey = kgen.generateKey();
    // this is the improperly padded plaintext

    c.init(Cipher.ENCRYPT_MODE, skey);
    // encrypt plaintext
    byte[] cipher = c.doFinal(PLAIN_TEXT);
    AlgorithmParameters params = c.getParameters();
    // generate cipher that enforces PKCS5 padding
    c = Cipher.getInstance("DES/CBC/PKCS5Padding", provider);
    c.init(Cipher.DECRYPT_MODE, skey, params);
    try {
        c.doFinal(cipher);
        throw new RuntimeException(
                "ERROR: Expected BadPaddingException not thrown");
    } catch (BadPaddingException expected) {
        out.println("Expected BadPaddingException thrown");
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:TextPKCS5PaddingTest.java

示例3: ECKey

import java.security.Provider; //導入依賴的package包/類
/**
 * Pair a private key with a public EC point.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, @Nullable PrivateKey privKey, ECPoint pub) {
    this.provider = provider;

    if (privKey == null || isECPrivateKey(privKey)) {
        this.privKey = privKey;
    } else {
        throw new IllegalArgumentException(
            "Expected EC private key, given a private key object with class " +
            privKey.getClass().toString() +
            " and algorithm " + privKey.getAlgorithm());
    }

    if (pub == null) {
        throw new IllegalArgumentException("Public key may not be null");
    } else {
        this.pub = pub;
    }
}
 
開發者ID:Aptoide,項目名稱:AppCoins-ethereumj,代碼行數:24,代碼來源:ECKey.java

示例4: main

import java.security.Provider; //導入依賴的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

示例5: main

import java.security.Provider; //導入依賴的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:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:PBESealedObject.java

示例6: verify

import java.security.Provider; //導入依賴的package包/類
/**
 * Verifies that this CRL was signed using the
 * private key that corresponds to the given public key,
 * and that the signature verification was computed by
 * the given provider. Note that the specified Provider object
 * does not have to be registered in the provider list.
 *
 * @param key the PublicKey used to carry out the verification.
 * @param sigProvider the signature provider.
 *
 * @exception NoSuchAlgorithmException on unsupported signature
 * algorithms.
 * @exception InvalidKeyException on incorrect key.
 * @exception SignatureException on signature errors.
 * @exception CRLException on encoding errors.
 */
public synchronized void verify(PublicKey key, Provider sigProvider)
        throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
        SignatureException {

    if (signedCRL == null) {
        throw new CRLException("Uninitialized CRL");
    }
    Signature sigVerf = null;
    if (sigProvider == null) {
        sigVerf = Signature.getInstance(sigAlgId.getName());
    } else {
        sigVerf = Signature.getInstance(sigAlgId.getName(), sigProvider);
    }
    sigVerf.initVerify(key);

    if (tbsCertList == null) {
        throw new CRLException("Uninitialized CRL");
    }

    sigVerf.update(tbsCertList, 0, tbsCertList.length);

    if (!sigVerf.verify(signature)) {
        throw new SignatureException("Signature does not match.");
    }
    verifiedPublicKey = key;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:43,代碼來源:X509CRLImpl.java

示例7: main

import java.security.Provider; //導入依賴的package包/類
@Override
public void main(Provider p) throws Exception {
    SecureRandom random;
    try {
        random = SecureRandom.getInstance("PKCS11");
    } catch (NoSuchAlgorithmException e) {
        System.out.println("Provider " + p + " does not support SecureRandom, skipping");
        e.printStackTrace();
        return;
    }
    byte[] b = new byte[32];
    random.nextBytes(b);
    System.out.println(toString(b));
    random.setSeed(b);
    random.nextBytes(b);
    System.out.println(toString(b));
    System.out.println("OK");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Basic.java

示例8: main

import java.security.Provider; //導入依賴的package包/類
@Override
public void main(Provider p) {
    List<String> algorithms = getSupportedAlgorithms("Mac", "Hmac", p);
    boolean success = true;
    for (String alg : algorithms) {
        try {
            doTest(alg, p);
        } catch (Exception e) {
            System.out.println("Unexpected exception: " + e);
            e.printStackTrace();
            success = false;
        }
    }

    if (!success) {
        throw new RuntimeException("Test failed");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:MacSameTest.java

示例9: testProviderInstallationAtRuntime

import java.security.Provider; //導入依賴的package包/類
@BeforeClass
public static void testProviderInstallationAtRuntime() {

    /* install wolfJCE provider at runtime */
    Security.addProvider(new WolfCryptProvider());

    Provider p = Security.getProvider("wolfJCE");
    assertNotNull(p);

    /* build list of enabled curves and key sizes,
     * getCurveSizeFromName() will return 0 if curve not found */
    Ecc tmp = new Ecc();
    for (int i = 0; i < supportedCurves.length; i++) {

        int size = tmp.getCurveSizeFromName(
                    supportedCurves[i].toUpperCase());

        if (size > 0) {
            enabledCurves.add(supportedCurves[i]);

            if (!enabledKeySizes.contains(new Integer(size))) {
                enabledKeySizes.add(new Integer(size));
            }
        }
    }
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:27,代碼來源:WolfCryptKeyPairGeneratorTest.java

示例10: testKeyAgreement

import java.security.Provider; //導入依賴的package包/類
private static void testKeyAgreement(KeyPair kpA, KeyPair kpB, Provider p)
    throws Exception {
    KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", p);
    ka1.init(kpA.getPrivate());
    ka1.doPhase(kpB.getPublic(), true);
    byte[] s1 = ka1.generateSecret();

    KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", p);
    ka2.init(kpB.getPrivate());
    ka2.doPhase(kpA.getPublic(), true);
    byte[] s2 = ka2.generateSecret();
    if (Arrays.equals(s1, s2) == false) {
        System.out.println("expected: " + toString(s1));
        System.out.println("actual:   " + toString(s2));
        throw new Exception("Generated secrets do not match");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:TestECDH2.java

示例11: crypt

import java.security.Provider; //導入依賴的package包/類
static byte[] crypt(
    boolean encrypt,
    String provider,
    byte[] bytes,
    char[] password,
    String dekAlgName,
    byte[] iv)
    throws IOException
{
    Provider prov = null;
    if (provider != null)
    {
        prov = Security.getProvider(provider);
        if (prov == null)
        {
            throw new EncryptionException("cannot find provider: " + provider);
        }
    }

    return crypt(encrypt, prov, bytes, password, dekAlgName, iv);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:22,代碼來源:PEMReader.java

示例12: testSigning

import java.security.Provider; //導入依賴的package包/類
private static void testSigning(Provider p, String algorithm,
        byte[] data, KeyPair kp1, KeyPair kp2) throws Exception {
    System.out.print("  " + algorithm);
    Signature s = Signature.getInstance(algorithm, p);
    s.initSign(kp1.getPrivate());
    s.update(data);
    byte[] sig = s.sign();

    s = Signature.getInstance(algorithm, p);
    s.initVerify(kp1.getPublic());
    s.update(data);
    boolean r = s.verify(sig);
    if (r == false) {
        throw new Exception("Signature did not verify");
    }

    s.initVerify(kp2.getPublic());
    s.update(data);
    r = s.verify(sig);
    if (r) {
        throw new Exception("Signature should not verify");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TestCurves.java

示例13: addAllMechsFromProvider

import java.security.Provider; //導入依賴的package包/類
/**
 * Helper routine to go through all properties contined in a
 * provider and add its mechanisms to the list of supported
 * mechanisms. If no default mechanism has been assinged so far,
 * it sets the default MechanismFactory and Oid as well.
 * @param p the provider to query
 * @return true if there is at least one mechanism that this
 * provider contributed, false otherwise
 */
private boolean addAllMechsFromProvider(Provider p) {

    String prop;
    boolean retVal = false;

    // Get all props for this provider
    Enumeration<Object> props = p.keys();

    // See if there are any GSS prop's
    while (props.hasMoreElements()) {
        prop = (String) props.nextElement();
        if (isMechFactoryProperty(prop)) {
            // Ok! This is a GSS provider!
            try {
                Oid mechOid = getOidFromMechFactoryProperty(prop);
                mechs.add(mechOid);
                retVal = true;
            } catch (GSSException e) {
                // Skip to next property
                GSSUtil.debug("Ignore the invalid property " +
                              prop + " from provider " + p.getName());
            }
        } // Processed GSS property
    } // while loop

    return retVal;

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:ProviderList.java

示例14: AbstractXMLRSSTest

import java.security.Provider; //導入依賴的package包/類
public AbstractXMLRSSTest(String algorithm, Provider provider, KeyPair keyPair) {
    Security.insertProviderAt(provider, 1);
    this.algorithm = algorithm;
    this.providerName = provider.getName();
    this.provider = provider;
    AbstractXMLRSSTest.keyPair = keyPair;
}
 
開發者ID:woefe,項目名稱:xmlrss,代碼行數:8,代碼來源:AbstractXMLRSSTest.java

示例15: fromInstructionFile

import java.security.Provider; //導入依賴的package包/類
/**
 * @return a non-null content crypto material.
 */
static ContentCryptoMaterial fromInstructionFile(
        Map<String, String> instFile,
        EncryptionMaterialsAccessor kekMaterialAccessor,
        Provider securityProvider,
        boolean keyWrapExpected,
        AWSKMS kms) {
    return fromInstructionFile0(instFile, kekMaterialAccessor,
            securityProvider, null, NONE, keyWrapExpected, kms);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:13,代碼來源:ContentCryptoMaterial.java


注:本文中的java.security.Provider類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。