javax.crypto.spec.RC2ParameterSpec Java Examples

The following examples show how to use javax.crypto.spec.RC2ParameterSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RC2Cipher.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #2
Source File: RC2Cipher.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #3
Source File: RC2Parameters.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #4
Source File: RC2Parameters.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #5
Source File: RC2Cipher.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #6
Source File: RC2Parameters.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #7
Source File: RC2Parameters.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #8
Source File: RC2Cipher.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #9
Source File: RC2Parameters.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #10
Source File: RC2Parameters.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #11
Source File: RC2Parameters.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #12
Source File: RC2Cipher.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #13
Source File: RC2Cipher.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #14
Source File: RC2.java    From ripple-lib-java with ISC License 6 votes vote down vote up
protected AlgorithmParameterSpec localEngineGetParameterSpec(
    Class paramSpec)
    throws InvalidParameterSpecException
{
    if (paramSpec == RC2ParameterSpec.class)
    {
        if (parameterVersion != -1)
        {
            if (parameterVersion < 256)
            {
                return new RC2ParameterSpec(ekb[parameterVersion], iv);
            }
            else
            {
                return new RC2ParameterSpec(parameterVersion, iv);
            }
        }
    }

    if (paramSpec == IvParameterSpec.class)
    {
        return new IvParameterSpec(iv);
    }

    throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object.");
}
 
Example #15
Source File: RC2Parameters.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #16
Source File: RC2Parameters.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #17
Source File: RC2Cipher.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #18
Source File: RC2Parameters.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #19
Source File: RC2Cipher.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #20
Source File: RC2Parameters.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #21
Source File: RC2Cipher.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params.getAlgorithm().equals("RC2")) {
        try {
            RC2ParameterSpec rc2Params =
                    params.getParameterSpec(RC2ParameterSpec.class);
            engineInit(opmode, key, rc2Params, random);
        } catch (InvalidParameterSpecException ipse) {
            throw new InvalidAlgorithmParameterException
                        ("Wrong parameter type: RC2 expected");
        }
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
        core.init(opmode, key, params, random);
    }
}
 
Example #22
Source File: RC2Parameters.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #23
Source File: RC2Parameters.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example #24
Source File: RC2Cipher.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params instanceof RC2ParameterSpec) {
        embeddedCipher.initEffectiveKeyBits
            (((RC2ParameterSpec)params).getEffectiveKeyBits());
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
    }
    core.init(opmode, key, params, random);
}
 
Example #25
Source File: RC2Cipher.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params instanceof RC2ParameterSpec) {
        embeddedCipher.initEffectiveKeyBits
            (((RC2ParameterSpec)params).getEffectiveKeyBits());
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
    }
    core.init(opmode, key, params, random);
}
 
Example #26
Source File: RC2AlgorithmParameters.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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())) {
        throw new Exception("ivs should be equal");
    }

    // test encoding and decoding
    byte[] encoded = rc2Params.getEncoded();
    AlgorithmParameters params = AlgorithmParameters.getInstance("RC2");
    params.init(encoded);

    // test RC2 AlgorithmParameters with RC2 Cipher
    rc2Cipher.init(Cipher.ENCRYPT_MODE,
        new SecretKeySpec("secret".getBytes("ASCII"), "RC2"), params);

    // get IV
    iv = rc2Cipher.getIV();
    if (!Arrays.equals(iv, rc2Spec.getIV())) {
        throw new Exception("ivs should be equal");
    }
    return encoded;
}
 
Example #27
Source File: RC2AlgorithmParameters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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())) {
        throw new Exception("ivs should be equal");
    }

    // test encoding and decoding
    byte[] encoded = rc2Params.getEncoded();
    AlgorithmParameters params = AlgorithmParameters.getInstance("RC2");
    params.init(encoded);

    // test RC2 AlgorithmParameters with RC2 Cipher
    rc2Cipher.init(Cipher.ENCRYPT_MODE,
        new SecretKeySpec("secret".getBytes("ASCII"), "RC2"), params);

    // get IV
    iv = rc2Cipher.getIV();
    if (!Arrays.equals(iv, rc2Spec.getIV())) {
        throw new Exception("ivs should be equal");
    }
    return encoded;
}
 
Example #28
Source File: RC2AlgorithmParameters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        byte[] iv_1 = {
            (byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,
            (byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,
            (byte)0x33,(byte)0x33
        };

        // check that RC2 is supported by our provider
        AlgorithmParameters rc2Params =
           AlgorithmParameters.getInstance("RC2", "SunJCE");

        // check that getAlgorithm returns "RC2"
        if (!rc2Params.getAlgorithm().equals("RC2")) {
            throw new Exception("getAlgorithm() returned "
                + rc2Params.getAlgorithm() + " instead of RC2");
        }

        // test parameters with effective key size and iv
        byte[] encoded = testParams(rc2Params, new RC2ParameterSpec(2, iv_1));

        // test parameters with just iv
        encoded = testParams(AlgorithmParameters.getInstance("RC2"),
            new RC2ParameterSpec(0, iv_1));

        // test vectors in RFC 2268
        runTests(tests);
    }
 
Example #29
Source File: RC2AlgorithmParameters.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        byte[] iv_1 = {
            (byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,
            (byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,
            (byte)0x33,(byte)0x33
        };

        // check that RC2 is supported by our provider
        AlgorithmParameters rc2Params =
           AlgorithmParameters.getInstance("RC2", "SunJCE");

        // check that getAlgorithm returns "RC2"
        if (!rc2Params.getAlgorithm().equals("RC2")) {
            throw new Exception("getAlgorithm() returned "
                + rc2Params.getAlgorithm() + " instead of RC2");
        }

        // test parameters with effective key size and iv
        byte[] encoded = testParams(rc2Params, new RC2ParameterSpec(2, iv_1));

        // test parameters with just iv
        encoded = testParams(AlgorithmParameters.getInstance("RC2"),
            new RC2ParameterSpec(0, iv_1));

        // test vectors in RFC 2268
        runTests(tests);
    }
 
Example #30
Source File: RC2Cipher.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void engineInit(int opmode, Key key,
        AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params != null && params instanceof RC2ParameterSpec) {
        embeddedCipher.initEffectiveKeyBits
            (((RC2ParameterSpec)params).getEffectiveKeyBits());
    } else {
        embeddedCipher.initEffectiveKeyBits(0);
    }
    core.init(opmode, key, params, random);
}