Examples of RC2ParameterSpec


Examples of javax.crypto.spec.RC2ParameterSpec

                param = new KeyParameter(key.getEncoded());
            }
        }
        else if (params instanceof RC2ParameterSpec)
        {
            RC2ParameterSpec    rc2Param = (RC2ParameterSpec)params;

            param = new RC2Parameters(key.getEncoded(), ((RC2ParameterSpec)params).getEffectiveKeyBits());

            if (rc2Param.getIV() != null && ivLength != 0)
            {
                param = new ParametersWithIV(param, rc2Param.getIV());
                ivParam = (ParametersWithIV)param;
            }
        }
        else if (params instanceof RC5ParameterSpec)
        {
View Full Code Here

Examples of javax.crypto.spec.RC2ParameterSpec

    
  // Encrypte the text and return the base64 string
  public String encrypt(String text, String passphrase, int keylen) {
   
   
    RC2ParameterSpec parm = new RC2ParameterSpec(keylen);
    
    try {
      // Get a MD5 for the passphrase
       MessageDigest md = MessageDigest.getInstance("MD5");
       // NB Use specific Charset
View Full Code Here

Examples of javax.crypto.spec.RC2ParameterSpec

   
    return null;
  }
  // Decrypt the base64 text and return the unsecure text
  public String decrypt(String text, String passphrase, int keylen) {
    RC2ParameterSpec parm = new RC2ParameterSpec(keylen);
      MessageDigest md;
    try {
      // Get a MD5 for the passphrase
      md = MessageDigest.getInstance("MD5");
      md.update(passphrase.getBytes(getCharset()));
View Full Code Here

Examples of javax.crypto.spec.RC2ParameterSpec

        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();
    }
View Full Code Here

Examples of javax.crypto.spec.RC2ParameterSpec

    protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
        throws InvalidParameterSpecException {

        if (RC2ParameterSpec.class.isAssignableFrom(paramSpec)) {
            return (iv == null ?
                    new RC2ParameterSpec(effectiveKeySize) :
                    new RC2ParameterSpec(effectiveKeySize, iv));
        } else {
            throw new InvalidParameterSpecException
                ("Inappropriate parameter specification");
        }
    }
View Full Code Here

Examples of javax.crypto.spec.RC2ParameterSpec

    protected void engineInit(int opmode, Key key,
            AlgorithmParameters params, SecureRandom random)
            throws InvalidKeyException, InvalidAlgorithmParameterException {
        if (params != null && params.getAlgorithm().equals("RC2")) {
            try {
                RC2ParameterSpec rc2Params = (RC2ParameterSpec)
                    params.getParameterSpec(RC2ParameterSpec.class);
                engineInit(opmode, key, rc2Params, random);
            } catch (InvalidParameterSpecException ipse) {
                throw new InvalidAlgorithmParameterException
                            ("Wrong parameter type: RC2 expected");
View Full Code Here

Examples of javax.crypto.spec.RC2ParameterSpec

    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

Examples of javax.crypto.spec.RC2ParameterSpec

        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

Examples of javax.crypto.spec.RC2ParameterSpec

     */
    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

Examples of javax.crypto.spec.RC2ParameterSpec

     */
    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
TOP
Copyright © 2018 www.massapi.com. 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.