Java 8 AlgorithmParameters - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AlgorithmParameters class.

This code example shows how to use the following methods: getEncoded, getParameterSpec, init
 
    private static byte[] testParams(AlgorithmParameters rc2Params,
        RC2ParameterSpec rc2Spec) throws Exception {
 
        // test getParameterSpec returns object equal to input 
        rc2Params.init(rc2Spec);
        RC2ParameterSpec rc2OtherSpec = (RC2ParameterSpec)
            rc2Params.getParameterSpec(RC2ParameterSpec.class);
        if (!rc2Spec.equals(rc2OtherSpec)) {
            throw new Exception("AlgorithmParameterSpecs should be equal");
        } 
 
        // test RC2ParameterSpec with RC2 Cipher 
        Cipher rc2Cipher = Cipher.getInstance("RC2/CBC/PKCS5PADDING", "SunJCE");
        rc2Cipher.init(Cipher.ENCRYPT_MODE,
            new SecretKeySpec("secret".getBytes("ASCII"), "RC2"), rc2Spec);
 
        // get IV 
        byte[] iv = rc2Cipher.getIV();
        if (!Arrays.equals(iv, rc2Spec.getIV())) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: init
        throws IOException 
    { 
        // we try ASN.1 explicitly first just in case and then role back to the default. 
        try 
        { 
            params.init(sParams.toASN1Primitive().getEncoded(), "ASN.1");
        } 
        catch (Exception ex)
        { 
            params.init(sParams.toASN1Primitive().getEncoded());
        } 
    } 
} 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getEncoded, getParameterSpec
            fail("JCE decrypt with additional data and GCMParameterSpec failed."); 
        } 
 
        AlgorithmParameters algParams = eax.getParameters();
 
        byte[] encParams = algParams.getEncoded();
 
        GCMParameters gcmParameters = GCMParameters.getInstance(encParams);
 
        if (!Arrays.areEqual(spec.getIV(), gcmParameters.getNonce()) || spec.getTLen() != gcmParameters.getIcvLen())
        { 
            fail("parameters mismatch"); 
        } 
 
        GCMParameterSpec gcmSpec = algParams.getParameterSpec(GCMParameterSpec.class);
 
        if (!Arrays.areEqual(gcmSpec.getIV(), gcmParameters.getNonce()) || gcmSpec.getTLen() != gcmParameters.getIcvLen())
        { 
            fail("spec parameters mismatch"); 
        } 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getEncoded, getParameterSpec, init
 
    private static byte[] testParams(AlgorithmParameters rc2Params,
        RC2ParameterSpec rc2Spec) throws Exception {
 
        // test getParameterSpec returns object equal to input 
        rc2Params.init(rc2Spec);
        RC2ParameterSpec rc2OtherSpec = (RC2ParameterSpec)
            rc2Params.getParameterSpec(RC2ParameterSpec.class);
        if (!rc2Spec.equals(rc2OtherSpec)) {
            throw new Exception("AlgorithmParameterSpecs should be equal");
        } 
 
        // test RC2ParameterSpec with RC2 Cipher 
        Cipher rc2Cipher = Cipher.getInstance("RC2/CBC/PKCS5PADDING", "SunJCE");
        rc2Cipher.init(Cipher.ENCRYPT_MODE,
            new SecretKeySpec("secret".getBytes("ASCII"), "RC2"), rc2Spec);
 
        // get IV 
        byte[] iv = rc2Cipher.getIV();
        if (!Arrays.equals(iv, rc2Spec.getIV())) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getEncoded, getParameterSpec
AlgorithmParameterGenerator a = AlgorithmParameterGenerator.getInstance("ElGamal", "BC");
        a.init(size, new SecureRandom());
        AlgorithmParameters params = a.generateParameters();
 
        byte[] encodeParams = params.getEncoded();
 
        AlgorithmParameters a2 = AlgorithmParameters.getInstance("ElGamal", "BC");
        a2.init(encodeParams);
 
        // a and a2 should be equivalent! 
        byte[] encodeParams_2 = a2.getEncoded();
 
        if (!areEqual(encodeParams, encodeParams_2))
        { 
            fail(this.getName() + ": encode/decode parameters failed");
        } 
 
        DHParameterSpec elP = (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getEncoded
        return params;
    } 
 
    void saveParameters(final Cipher cipher) throws IOException {
        final AlgorithmParameters params = cipher.getParameters();
        final byte[] encodedParams = params.getEncoded();
        FileUtils.writeByteArrayToFile(paramsFile, encodedParams);
    } 
 
    boolean checkKeyValid(byte[] key, byte[] validator) throws GeneralSecurityException {
        final byte[] salt = Arrays.copyOf(validator, VALIDATOR_SALT_BYTES);
        return Arrays.equals(validator, createValidator(key, salt));
    } 
 
    byte[] createValidator(byte []key) throws GeneralSecurityException {
        // generate new salt bytes 
        final byte[] salt = new byte[VALIDATOR_SALT_BYTES];
        secureRandom.nextBytes(salt);
        return createValidator(key, salt);
    } 
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getEncoded, getParameterSpec, init
 
    private static byte[] testParams(AlgorithmParameters rc2Params,
        RC2ParameterSpec rc2Spec) throws Exception {
 
        // test getParameterSpec returns object equal to input 
        rc2Params.init(rc2Spec);
        RC2ParameterSpec rc2OtherSpec = (RC2ParameterSpec)
            rc2Params.getParameterSpec(RC2ParameterSpec.class);
        if (!rc2Spec.equals(rc2OtherSpec)) {
            throw new Exception("AlgorithmParameterSpecs should be equal");
        } 
 
        // test RC2ParameterSpec with RC2 Cipher 
        Cipher rc2Cipher = Cipher.getInstance("RC2/CBC/PKCS5PADDING", "SunJCE");
        rc2Cipher.init(Cipher.ENCRYPT_MODE,
            new SecretKeySpec("secret".getBytes("ASCII"), "RC2"), rc2Spec);
 
        // get IV 
        byte[] iv = rc2Cipher.getIV();
        if (!Arrays.equals(iv, rc2Spec.getIV())) {

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getEncoded
    public AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier algId, AlgorithmParameters parameters)
        throws InvalidAlgorithmParameterException 
    { 
        try 
        { 
            ASN1Encodable params = ASN1Primitive.fromByteArray(parameters.getEncoded());
 
            return new AlgorithmIdentifier(algId, params);
        } 
        catch (IOException e)
        { 
            throw new InvalidAlgorithmParameterException("unable to encode parameters object: " + e.getMessage());
        } 
    } 
 
    public AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier algorithm, AlgorithmParameterSpec algorithmSpec)
        throws InvalidAlgorithmParameterException 
    { 
        if (algorithmSpec instanceof OAEPParameterSpec)
        { 
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getEncoded
    { 
        // we try ASN.1 explicitly first just in case and then role back to the default. 
        ASN1Encodable asn1Params;
        try 
        { 
            asn1Params = ASN1Primitive.fromByteArray(params.getEncoded("ASN.1"));
        } 
        catch (Exception ex)
        { 
            asn1Params = ASN1Primitive.fromByteArray(params.getEncoded());
        } 
 
        return asn1Params;
    } 
 
    /** 
     * Load an AlgorithmParameters object with the passed in ASN.1 encodable - if possible. 
     * 
     * @param params the AlgorithmParameters object to be initialised. 
     * @param sParams the ASN.1 encodable to initialise params with. 
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getParameterSpec
        byte[] sampleMessage = new byte[1000 + random.nextInt(100)];
        random.nextBytes(sampleMessage);
 
        Signature normalSig = Signature.getInstance(sigName, "BC");
 
        PSSParameterSpec spec = (PSSParameterSpec)normalSig.getParameters().getParameterSpec(PSSParameterSpec.class);
 
        // Make sure we generate the same 'random' salt for both normal and raw signers 
        int saltLen = spec.getSaltLength();
        byte[] fixedRandomBytes = new byte[saltLen];
        random.nextBytes(fixedRandomBytes);
 
        normalSig.initSign(privKey, new FixedSecureRandom(fixedRandomBytes));
        normalSig.update(sampleMessage);
        byte[] normalResult = normalSig.sign();
 
        MessageDigest digest = MessageDigest.getInstance(digestOID.getId(), "BC");
        byte[] hash = digest.digest(sampleMessage);
 
        Signature rawSig = Signature.getInstance("RAWRSASSA-PSS", "BC");
Full Snippet Info
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 AlgorithmParameters Methods: