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


Java InvalidAlgorithmParameterException類代碼示例

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


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

示例1: createNewKey

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
/**
 * Create a new key in the Keystore
 */
private void createNewKey(){
  try {
    final KeyStore keyStore = KeyStore.getInstance(AndroidKeyStore);
    keyStore.load(null);

    final KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, AndroidKeyStore);

    // Build one key to be used for encrypting and decrypting the file
    keyGenerator.init(
        new KeyGenParameterSpec.Builder(ALIAS,
            KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
            .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
            .build());
    keyGenerator.generateKey();
    Log.i(TAG, "Key created in Keystore");

  }catch (KeyStoreException | InvalidAlgorithmParameterException | NoSuchProviderException | NoSuchAlgorithmException | CertificateException | IOException  kS){
    Log.e(TAG, kS.getMessage());
  }
}
 
開發者ID:Esri,項目名稱:mapbook-android,代碼行數:25,代碼來源:CredentialCryptographer.java

示例2: createFor

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
public static InputStream createFor(MasterSecret masterSecret, File file)
    throws IOException
{
  try {
    if (file.length() <= IV_LENGTH + MAC_LENGTH) {
      throw new IOException("File too short");
    }

    verifyMac(masterSecret, file);

    FileInputStream fileStream = new FileInputStream(file);
    byte[]          ivBytes    = new byte[IV_LENGTH];
    readFully(fileStream, ivBytes);

    Cipher          cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    IvParameterSpec iv     = new IvParameterSpec(ivBytes);
    cipher.init(Cipher.DECRYPT_MODE, masterSecret.getEncryptionKey(), iv);

    return new CipherInputStreamWrapper(new LimitedInputStream(fileStream, file.length() - MAC_LENGTH - IV_LENGTH), cipher);
  } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException e) {
    throw new AssertionError(e);
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:24,代碼來源:DecryptingPartInputStream.java

示例3: newTransform

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
public Transform newTransform(String algorithm,
    TransformParameterSpec params) throws NoSuchAlgorithmException,
    InvalidAlgorithmParameterException {

    TransformService spi;
    if (getProvider() == null) {
        spi = TransformService.getInstance(algorithm, "DOM");
    } else {
        try {
            spi = TransformService.getInstance(algorithm, "DOM", getProvider());
        } catch (NoSuchAlgorithmException nsae) {
            spi = TransformService.getInstance(algorithm, "DOM");
        }
    }

    spi.init(params);
    return new DOMTransform(spi);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:DOMXMLSignatureFactory.java

示例4: engineInit

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
@Override
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:17,代碼來源:JDKAlgorithmParameterGenerator.java

示例5: engineInit

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
/**
 * Initializes this parameter generator with a set of
 * algorithm-specific parameter generation values.
 *
 * @param genParamSpec the set of algorithm-specific parameter
 *        generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
        SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DSAGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException("Invalid parameter");
    }
    DSAGenParameterSpec dsaGenParams = (DSAGenParameterSpec)genParamSpec;

    // directly initialize using the already validated values
    this.valueL = dsaGenParams.getPrimePLength();
    this.valueN = dsaGenParams.getSubprimeQLength();
    this.seedLen = dsaGenParams.getSeedLength();
    this.random = random;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:DSAParameterGenerator.java

示例6: encrypt

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
public static String encrypt(String str) {
    if (str == null) return null;
    Cipher cipher;
    try {
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, keySpec,
                new IvParameterSpec(ips.getBytes("UTF-8")));

        byte[] encrypted = cipher.doFinal(str.getBytes("UTF-8"));
        String Str = new String(Base64.encodeBase64(encrypted));
        return Str;
    } catch (NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | InvalidAlgorithmParameterException
            | IllegalBlockSizeException | BadPaddingException
            | UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:20,代碼來源:AES256.java

示例7: encrypt

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
public byte[] encrypt(int version, byte[] data) {
    CryptVersion cryptVersion = cryptVersion(version);
    try {
        int cryptedLength = cryptVersion.encryptedLength.apply(data.length);
        byte[] result = new byte[cryptedLength + cryptVersion.saltLength + 1];
        result[0] = toSignedByte(version);

        byte[] random = urandomBytes(cryptVersion.saltLength);
        IvParameterSpec iv_spec = new IvParameterSpec(random);
        System.arraycopy(random, 0, result, 1, cryptVersion.saltLength);

        Cipher cipher = cipher(cryptVersion.cipher);
        cipher.init(Cipher.ENCRYPT_MODE, cryptVersion.key, iv_spec);
        int len = cipher.doFinal(data, 0, data.length, result, cryptVersion.saltLength + 1);

        if (len < cryptedLength) LOG.info("len was " + len + " instead of " + cryptedLength);

        return result;
    } catch (ShortBufferException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) {
        throw new RuntimeException("JCE exception caught while encrypting with version " + version, e);
    }
}
 
開發者ID:bolcom,項目名稱:spring-data-mongodb-encrypt,代碼行數:23,代碼來源:CryptVault.java

示例8: decrypt

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
public static String decrypt(String str) {
    if (str == null) return null;
    Cipher cipher;
    try {
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, keySpec,
                new IvParameterSpec(ips.getBytes("UTF-8")));

        byte[] byteStr = Base64.decodeBase64(str.getBytes());

        return new String(cipher.doFinal(byteStr), "UTF-8");
    } catch (NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | InvalidAlgorithmParameterException
            | IllegalBlockSizeException | BadPaddingException
            | UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:JoMingyu,項目名稱:Daejeon-People,代碼行數:20,代碼來源:AES256.java

示例9: ValidatorParams

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
ValidatorParams(PKIXParameters params)
    throws InvalidAlgorithmParameterException
{
    if (params instanceof PKIXExtendedParameters) {
        timestamp = ((PKIXExtendedParameters) params).getTimestamp();
        variant = ((PKIXExtendedParameters) params).getVariant();
    }

    this.anchors = params.getTrustAnchors();
    // Make sure that none of the trust anchors include name constraints
    // (not supported).
    for (TrustAnchor anchor : this.anchors) {
        if (anchor.getNameConstraints() != null) {
            throw new InvalidAlgorithmParameterException
                ("name constraints in trust anchor not supported");
        }
    }
    this.params = params;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:PKIX.java

示例10: registerUser

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
@BeforeClass(enabled = false)
public void registerUser() throws CipherException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
    dsp = createNewMember(2, 100)
            .thenApply(papyrusMember -> {
                allTransactionsMinedAsync(asList(papyrusMember.refillTransaction, papyrusMember.mintTransaction));
                return papyrusMember;
            }).join();
    dspRegistrar = createNewMember(2, 100)
            .thenApply(papyrusMember -> {
                allTransactionsMinedAsync(asList(papyrusMember.refillTransaction, papyrusMember.mintTransaction));
                return papyrusMember;
            }).join();
    dao = loadDaoContract(dsp.transactionManager);
    daoRegistrar = loadDaoContract(dspRegistrar.transactionManager);
    token = asCf(dao.token()).thenApply(tokenAddress -> loadTokenContract(tokenAddress.toString(), dsp.transactionManager)).join();
    tokenRegistrar = asCf(daoRegistrar.token())
            .thenApply(tokenAddress -> loadTokenContract(tokenAddress.toString(), dspRegistrar.transactionManager)
            ).join();
    dspRegistry = asCf(daoRegistrar.dspRegistry())
            .thenApply(dspRegistryAddress -> loadDspRegistry(dspRegistryAddress.toString(), dsp.transactionManager))
            .join();
    initDepositContract();
}
 
開發者ID:papyrusglobal,項目名稱:smartcontracts,代碼行數:24,代碼來源:DSPTest.java

示例11: getSymmetricKey

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

示例12: setTrustAnchors

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
/**
 * Sets the {@code Set} of most-trusted CAs.
 * <p>
 * Note that the {@code Set} is copied to protect against
 * subsequent modifications.
 *
 * @param trustAnchors a {@code Set} of {@code TrustAnchor}s
 * @throws InvalidAlgorithmParameterException if the specified
 * {@code Set} is empty {@code (trustAnchors.isEmpty() == true)}
 * @throws NullPointerException if the specified {@code Set} is
 * {@code null}
 * @throws ClassCastException if any of the elements in the set
 * are not of type {@code java.security.cert.TrustAnchor}
 *
 * @see #getTrustAnchors
 */
public void setTrustAnchors(Set<TrustAnchor> trustAnchors)
    throws InvalidAlgorithmParameterException
{
    if (trustAnchors == null) {
        throw new NullPointerException("the trustAnchors parameters must" +
            " be non-null");
    }
    if (trustAnchors.isEmpty()) {
        throw new InvalidAlgorithmParameterException("the trustAnchors " +
            "parameter must be non-empty");
    }
    for (Iterator<TrustAnchor> i = trustAnchors.iterator(); i.hasNext(); ) {
        if (!(i.next() instanceof TrustAnchor)) {
            throw new ClassCastException("all elements of set must be "
                + "of type java.security.cert.TrustAnchor");
        }
    }
    this.unmodTrustAnchors = Collections.unmodifiableSet
            (new HashSet<>(trustAnchors));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:PKIXParameters.java

示例13: checkParams

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
private void checkParams(PKIXBuilderParameters params)
    throws InvalidAlgorithmParameterException
{
    CertSelector sel = targetCertConstraints();
    if (!(sel instanceof X509CertSelector)) {
        throw new InvalidAlgorithmParameterException("the "
            + "targetCertConstraints parameter must be an "
            + "X509CertSelector");
    }
    if (params instanceof SunCertPathBuilderParameters) {
        buildForward =
            ((SunCertPathBuilderParameters)params).getBuildForward();
    }
    this.params = params;
    this.targetSubject = getTargetSubject(
        certStores(), (X509CertSelector)targetCertConstraints());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:PKIX.java

示例14: registerUser

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
@BeforeClass(enabled = false)
public void registerUser() throws CipherException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
    auditor = createNewMember(2, 100)
            .thenApply(papyrusMember -> {
                allTransactionsMinedAsync(asList(papyrusMember.refillTransaction, papyrusMember.mintTransaction));
                return papyrusMember;
            }).join();
    auditorRegistrar = createNewMember(2, 100)
            .thenApply(papyrusMember -> {
                allTransactionsMinedAsync(asList(papyrusMember.refillTransaction, papyrusMember.mintTransaction));
                return papyrusMember;
            }).join();
    dao = loadDaoContract(auditor.transactionManager);
    daoRegistrar = loadDaoContract(auditorRegistrar.transactionManager);
    token = asCf(dao.token()).thenApply(tokenAddress -> loadTokenContract(tokenAddress.toString(), auditor.transactionManager)).join();
    tokenRegistrar = asCf(daoRegistrar.token())
            .thenApply(tokenAddress -> loadTokenContract(tokenAddress.toString(), auditorRegistrar.transactionManager)
            ).join();
    auditorRegistry = asCf(daoRegistrar.auditorRegistry())
            .thenApply(auditorRegistryAddress -> loadAuditorRegistry(auditorRegistryAddress.toString(), auditor.transactionManager))
            .join();
    initDepositContract();
}
 
開發者ID:papyrusglobal,項目名稱:smartcontracts,代碼行數:24,代碼來源:AuditorTest.java

示例15: actionMenuNotRegistered

import java.security.InvalidAlgorithmParameterException; //導入依賴的package包/類
private void actionMenuNotRegistered(final int choice) throws ClassNotFoundException, IOException, FileNotFoundException,
        InvalidKeyException, InvalidAlgorithmParameterException,
        InvalidKeySpecException, IllegalBlockSizeException, BadPaddingException, InvalidParameterSpecException {
    switch (choice) {
        case 1:
            signIn();
            break;

        case 2:
            signUp();
            break;
            
        case 3: // close with condition in while
            break;

        default:
            System.out.println("Unknow choice " + choice + "\n");
            break;

    }
}
 
開發者ID:StanIsAdmin,項目名稱:CrashCoin,代碼行數:22,代碼來源:ClientApplication.java


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