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


Java NoSuchProviderException类代码示例

本文整理汇总了Java中java.security.NoSuchProviderException的典型用法代码示例。如果您正苦于以下问题:Java NoSuchProviderException类的具体用法?Java NoSuchProviderException怎么用?Java NoSuchProviderException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testGenerateSeed

import java.security.NoSuchProviderException; //导入依赖的package包/类
@Test
public void testGenerateSeed()
    throws NoSuchProviderException, NoSuchAlgorithmException {

    byte[] valuesA = new byte[128];
    byte[] valuesB = new byte[128];

    SecureRandom rand = SecureRandom.getInstance("HashDRBG", "wolfJCE");

    valuesA = rand.generateSeed(valuesA.length);
    for (int i = 0; i < 10; i++) {
        valuesB = rand.generateSeed(valuesB.length);

        if(Arrays.equals(valuesA, valuesB))
            fail("SecureRandom generated two equal consecutive arrays");

        valuesA = Arrays.copyOf(valuesB, valuesB.length);
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:20,代码来源:WolfCryptRandomTest.java

示例2: generateECKeypair

import java.security.NoSuchProviderException; //导入依赖的package包/类
public static KeyPair generateECKeypair(ASN1ObjectIdentifier curveId, SecureRandom random)
        throws NoSuchAlgorithmException, NoSuchProviderException,
            InvalidAlgorithmParameterException {
    ParamUtil.requireNonNull("curveId", curveId);

    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(curveId.getId());
    KeyPairGenerator kpGen = getKeyPairGenerator("EC");
    synchronized (kpGen) {
        if (random == null) {
            kpGen.initialize(spec);
        } else {
            kpGen.initialize(spec, random);
        }
        return kpGen.generateKeyPair();
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:17,代码来源:KeyUtil.java

示例3: doEcDh

import java.security.NoSuchProviderException; //导入依赖的package包/类
@Override
public final byte[] doEcDh(final Key privateKey,
		             final byte[] publicKey,
		             final EcCurve curveName) throws NoSuchAlgorithmException,
		                                             InvalidKeyException,
		                                             InvalidKeySpecException {

	if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
		Security.insertProviderAt(new BouncyCastleProvider(), 1);
	}
	KeyAgreement ka = null;
	try {
		ka = KeyAgreement.getInstance(ECDH, BouncyCastleProvider.PROVIDER_NAME);

	}
	catch (final NoSuchProviderException e) {
		ka = KeyAgreement.getInstance(ECDH);
	}
	ka.init(privateKey);
	ka.doPhase(loadEcPublicKey(publicKey, curveName), true);
	return ka.generateSecret();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:23,代码来源:JseCryptoHelper.java

示例4: decrypt

import java.security.NoSuchProviderException; //导入依赖的package包/类
public String decrypt(final String alias, final byte[] encryptedData, Context appContext)
        throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException,
        NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IOException,
        BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException {

    final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
    String IV = PreferenceHelper.getPrefernceHelperInstace().getString(appContext, "IV", "");

    if (null != IV && !IV.isEmpty()) {
        byte[] encryptionIv = Base64.decode(IV, Base64.DEFAULT);
        Log.e("Decrypter", "IV : " + IV + " IV size " + encryptionIv.length);
        final GCMParameterSpec spec = new GCMParameterSpec(128, encryptionIv);
        cipher.init(Cipher.DECRYPT_MODE, getSecretKey(alias), spec);
        return new String(cipher.doFinal(encryptedData), "UTF-8");
    } else {
        return "{}";
    }
}
 
开发者ID:hiteshsahu,项目名称:FingerPrint-Authentication-With-React-Native-Android,代码行数:19,代码来源:Decrypter.java

示例5: createAlgorithmParameters

import java.security.NoSuchProviderException; //导入依赖的package包/类
AlgorithmParameters createAlgorithmParameters(ASN1ObjectIdentifier algorithm)
    throws NoSuchAlgorithmException, NoSuchProviderException
{
    String algorithmName = (String)BASE_CIPHER_NAMES.get(algorithm);

    if (algorithmName != null)
    {
        try
        {
            // this is reversed as the Sun policy files now allow unlimited strength RSA
            return helper.createAlgorithmParameters(algorithmName);
        }
        catch (NoSuchAlgorithmException e)
        {
            // Ignore
        }
    }
    return helper.createAlgorithmParameters(algorithm.getId());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:EnvelopedDataHelper.java

示例6: getSymmetricKey

import java.security.NoSuchProviderException; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public SecretKey getSymmetricKey(String alias)
        throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException,
        CertificateException, KeyStoreException, UnrecoverableEntryException {

    ESLog.v("%s=>getSymmetricKey(%s)", getClass().getSimpleName(), alias);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        KeyStore ks = KeyStore.getInstance(KEYSTORE_PROVIDER);
        ks.load(null);

        Key key = ks.getKey(alias, null);
        if (key != null) {

            ESLog.i("SecretKey found in KeyStore.");
            return (SecretKey) key;
        }
        ESLog.w("SecretKey not found in KeyStore.");
        return null;
    }

    UnsupportedOperationException unsupportedOperationException = new UnsupportedOperationException();
    ESLog.wtf("Unsupported operation. This code should be called only from M onwards.", unsupportedOperationException.getCause());
    throw unsupportedOperationException;
}
 
开发者ID:marius-bardan,项目名称:encryptedprefs,代码行数:26,代码来源:Vault.java

示例7: loadEcPublicKey

import java.security.NoSuchProviderException; //导入依赖的package包/类
private static Key loadEcPublicKey(final byte [] pubKey,
                                      final EcCurve curveName) throws NoSuchAlgorithmException,
                                                                      InvalidKeySpecException {
    final ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(curveName.toString());
    KeyFactory kf;
	try {
		kf = KeyFactory.getInstance(ECDH, BouncyCastleProvider.PROVIDER_NAME);
	}
	catch (final NoSuchProviderException e) {
		kf = KeyFactory.getInstance(ECDH);
	}
    final ECNamedCurveSpec params = new ECNamedCurveSpec(curveName.toString(), spec.getCurve(), spec.getG(), spec.getN());
    final ECPoint point =  ECPointUtil.decodePoint(params.getCurve(), pubKey);
    final java.security.spec.ECPublicKeySpec pubKeySpec = new java.security.spec.ECPublicKeySpec(point, params);
    return kf.generatePublic(pubKeySpec);
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:17,代码来源:JseCryptoHelper.java

示例8: test1

import java.security.NoSuchProviderException; //导入依赖的package包/类
@Test /* sign transaction  https://tools.ietf.org/html/rfc6979 */
public void test1() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, IOException {

    //python taken exact data
    String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80";
    // String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480";

    byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
    ECKey key = ECKey.fromPrivate(cowPrivKey);

    byte[] data = Hex.decode(txRLPRawData);

    // step 1: serialize + RLP encode
    // step 2: hash = keccak(step1)
    byte[] txHash = HashUtil.sha3(data);

    String signature = key.doSign(txHash).toBase64();
    System.out.println(signature);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:20,代码来源:TransactionTest.java

示例9: testShaSingleByteUpdate

import java.security.NoSuchProviderException; //导入依赖的package包/类
@Test
public void testShaSingleByteUpdate()
    throws NoSuchProviderException, NoSuchAlgorithmException {

    String input = "Hello World";
    byte[] inArray = input.getBytes();
    final byte expected[] = new byte[] {
        (byte)0x0a, (byte)0x4d, (byte)0x55, (byte)0xa8,
        (byte)0xd7, (byte)0x78, (byte)0xe5, (byte)0x02,
        (byte)0x2f, (byte)0xab, (byte)0x70, (byte)0x19,
        (byte)0x77, (byte)0xc5, (byte)0xd8, (byte)0x40,
        (byte)0xbb, (byte)0xc4, (byte)0x86, (byte)0xd0
    };

    byte[] output;

    MessageDigest sha = MessageDigest.getInstance("SHA-1", "wolfJCE");

    for (int i = 0; i < inArray.length; i++) {
        sha.update(inArray[i]);
    }
    output = sha.digest();
    assertEquals(expected.length, output.length);
    assertArrayEquals(expected, output);
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:26,代码来源:WolfCryptMessageDigestShaTest.java

示例10: testKeyPairGeneratorEccMultipleInits

import java.security.NoSuchProviderException; //导入依赖的package包/类
@Test
public void testKeyPairGeneratorEccMultipleInits()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidAlgorithmParameterException {

    if (enabledCurves.size() > 0) {

        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance("EC", "wolfJCE");

        ECGenParameterSpec ecSpec =
            new ECGenParameterSpec(enabledCurves.get(0));

        kpg.initialize(ecSpec);
        kpg.initialize(ecSpec);
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:18,代码来源:WolfCryptKeyPairGeneratorTest.java

示例11: runAll

import java.security.NoSuchProviderException; //导入依赖的package包/类
public void runAll() throws InvalidKeyException,
        NoSuchPaddingException, InvalidAlgorithmParameterException,
        ShortBufferException, IllegalBlockSizeException,
        BadPaddingException, NoSuchAlgorithmException,
        NoSuchProviderException {

    for (String mode : MODES) {
        for (String padding : PADDINGS) {
            if (!isMultipleKeyLengthSupported()) {
                runTest(mode, padding, minKeySize);
            } else {
                int keySize = maxKeySize;
                while (keySize >= minKeySize) {
                    out.println("With Key Strength: " + keySize);
                    runTest(mode, padding, keySize);
                    keySize -= KEYCUTTER;
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TestCipher.java

示例12: init

import java.security.NoSuchProviderException; //导入依赖的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

示例13: NetscapeCertRequest

import java.security.NoSuchProviderException; //导入依赖的package包/类
public NetscapeCertRequest(
    String challenge,
    AlgorithmIdentifier signing_alg,
    PublicKey pub_key) throws NoSuchAlgorithmException,
        InvalidKeySpecException, NoSuchProviderException
{

    this.challenge = challenge;
    sigAlg = signing_alg;
    pubkey = pub_key;

    ASN1EncodableVector content_der = new ASN1EncodableVector();
    content_der.add(getKeySpec());
    //content_der.add(new SubjectPublicKeyInfo(sigAlg, new RSAPublicKeyStructure(pubkey.getModulus(), pubkey.getPublicExponent()).getDERObject()));
    content_der.add(new DERIA5String(challenge));

    try
    {
        content = new DERBitString(new DERSequence(content_der));
    }
    catch (IOException e)
    {
        throw new InvalidKeySpecException("exception encoding key: " + e.toString());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:26,代码来源:NetscapeCertRequest.java

示例14: if

import java.security.NoSuchProviderException; //导入依赖的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

示例15: GCMParameterSpecTest

import java.security.NoSuchProviderException; //导入依赖的package包/类
/**
 * Initialize IV, IV with offset, plain text, AAD and SecretKey
 *
 * @param keyLength length of a secret key
 * @param tagLength tag length
 * @param IVlength IV length
 * @param offset offset in a buffer for IV
 * @param textLength plain text length
 * @param AADLength AAD length
 */
public GCMParameterSpecTest(int keyLength, int tagLength, int IVlength,
        int offset, int textLength, int AADLength)
        throws NoSuchAlgorithmException, NoSuchProviderException {
    this.tagLength = tagLength; // save tag length
    this.IVlength = IVlength; // save IV length
    this.offset = offset; // save IV offset

    // prepare IV
    IV = Helper.generateBytes(IVlength);

    // prepare IV with offset
    IVO = new byte[this.IVlength + this.offset];
    System.arraycopy(IV, 0, IVO, offset, this.IVlength);

    // prepare data
    data = Helper.generateBytes(textLength);

    // prepare AAD
    AAD = Helper.generateBytes(AADLength);

    // init a secret key
    KeyGenerator kg = KeyGenerator.getInstance("AES", "SunJCE");
    kg.init(keyLength);
    key = kg.generateKey();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:GCMParameterSpecTest.java


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