当前位置: 首页>>代码示例>>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;未经允许,请勿转载。