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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
See Code Examples for Java 8 AlgorithmParameters Methods: