Package javax.crypto.spec

Examples of javax.crypto.spec.RC2ParameterSpec


     */
    public void testEquals() {
        int effectiveKeyBits = 10;
        byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};

        RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv);
        RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv);
        RC2ParameterSpec ps3 = new RC2ParameterSpec(10,
                                    new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9});

        // checking for reflexive law:
        assertTrue("The equivalence relation should be reflexive.",
                                                        ps1.equals(ps1));

        assertTrue("Objects built on the same parameters should be equal.",
                                                        ps1.equals(ps2));
        // checking for symmetric law:
        assertTrue("The equivalence relation should be symmetric.",
                                                        ps2.equals(ps1));

        assertTrue("Objects built on the equal parameters should be equal.",
                                                        ps2.equals(ps3));

        // checking for transitive law:
        assertTrue("The equivalence relation should be transitive.",
                                                        ps1.equals(ps3));

        assertFalse("Should return not be equal to null object.",
                                                        ps1.equals(null));

        ps2 = new RC2ParameterSpec(11, iv);
        assertFalse("Objects should not be equal.", ps1.equals(ps2));

        ps2 = new RC2ParameterSpec(11, new byte[] {9, 8, 7, 6, 5, 4, 3, 2, 1});
        assertFalse("Objects should not be equal.", ps1.equals(ps2));
    }
View Full Code Here


     */
    public void testHashCode() {
        int effectiveKeyBits = 0;
        byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};

        RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv);
        RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv);

        assertTrue("Equal objects should have the same hash codes.",
                                            ps1.hashCode() == ps2.hashCode());
    }
View Full Code Here

     */
    public void testEquals() {
        int effectiveKeyBits = 10;
        byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};

        RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv);
        RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv);
        RC2ParameterSpec ps3 = new RC2ParameterSpec(10,
                                    new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9});

        // checking for reflexive law:
        assertTrue("The equivalence relation should be reflexive.",
                                                        ps1.equals(ps1));

        assertTrue("Objects built on the same parameters should be equal.",
                                                        ps1.equals(ps2));
        // checking for symmetric law:
        assertTrue("The equivalence relation should be symmetric.",
                                                        ps2.equals(ps1));

        assertTrue("Objects built on the equal parameters should be equal.",
                                                        ps2.equals(ps3));

        // checking for transitive law:
        assertTrue("The equivalence relation should be transitive.",
                                                        ps1.equals(ps3));

        assertFalse("Should return not be equal to null object.",
                                                        ps1.equals(null));

        ps2 = new RC2ParameterSpec(11, iv);
        assertFalse("Objects should not be equal.", ps1.equals(ps2));

        ps2 = new RC2ParameterSpec(11, new byte[] {9, 8, 7, 6, 5, 4, 3, 2, 1});
        assertFalse("Objects should not be equal.", ps1.equals(ps2));
    }
View Full Code Here

     */
    public void testHashCode() {
        int effectiveKeyBits = 0;
        byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};

        RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits, iv);
        RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits, iv);

        assertTrue("Equal objects should have the same hash codes.",
                                            ps1.hashCode() == ps2.hashCode());
    }
View Full Code Here

    public void testRC2ParameterSpec1() {
        int effectiveKeyBits = 10;
        byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8};

        try {
            new RC2ParameterSpec(effectiveKeyBits, null);
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of null iv.");
        } catch (IllegalArgumentException e) {
        }

        try {
            new RC2ParameterSpec(effectiveKeyBits, new byte[] {1, 2, 3, 4, 5});
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of short iv.");
        } catch (IllegalArgumentException e) {
        }

        RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv);
        iv[0] ++;
        assertFalse("The change of iv specified in the constructor "
                    + "should not cause the change of internal array.",
                    iv[0] == ps.getIV()[0]);
    }
View Full Code Here

        int effectiveKeyBits = 10;
        byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
        int offset = 2;

        try {
            new RC2ParameterSpec(effectiveKeyBits, null, offset);
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of null iv.");
        } catch (IllegalArgumentException e) {
        }

        try {
            new RC2ParameterSpec(effectiveKeyBits, iv, 4);
            fail("An IllegalArgumentException should be thrown "
                    + "in the case of short iv.");
        } catch (IllegalArgumentException e) {
        }

        RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv, offset);
        iv[offset] ++;
        assertFalse("The change of iv specified in the constructor "
                    + "should not cause the change of internal array.",
                    iv[offset] == ps.getIV()[0]);
    }
View Full Code Here

     */
    public void testGetEffectiveKeyBits() {
        int effectiveKeyBits = 10;
        byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8};

        RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv);
        assertTrue("The returned effectiveKeyBits value is not equal to the "
                + "value specified in the constructor.",
                effectiveKeyBits == ps.getEffectiveKeyBits());
    }
View Full Code Here

     */
    public void testGetIV() {
        int effectiveKeyBits = 10;
        byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};

        RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv);
        byte[] result = ps.getIV();
        if (! Arrays.equals(iv, result)) {
            fail("The returned iv is not equal to the specified "
                    + "in the constructor.");
        }
        result[0] ++;
        assertFalse("The change of returned by getIV() method iv "
                    + "should not cause the change of internal array.",
                    result[0] == ps.getIV()[0]);
        ps = new RC2ParameterSpec(effectiveKeyBits);
        assertNull("The getIV() method should return null if the parameter "
                    + "set does not contain iv.", ps.getIV());
    }
View Full Code Here

            if (vec == null) {
                cipher.init(cipherMode, key);
            } else {
                AlgorithmParameterSpec aps;
                if (cipherAlgorithm == CipherAlgorithm.rc2) {
                    aps = new RC2ParameterSpec(key.getEncoded().length*8, vec);
                } else {
                    aps = new IvParameterSpec(vec);
                }
                cipher.init(cipherMode, key, aps);
            }
View Full Code Here

            {
                if (parameterVersion != -1)
                {
                    if (parameterVersion < 256)
                    {
                        return new RC2ParameterSpec(ekb[parameterVersion], iv);
                    }
                    else
                    {
                        return new RC2ParameterSpec(parameterVersion, iv);
                    }
                }
            }

            if (paramSpec == IvParameterSpec.class)
View Full Code Here

TOP

Related Classes of javax.crypto.spec.RC2ParameterSpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.