[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug crypto/27849] New: getIV() call on cipher for DESede/CBC returns nu

From: vivekl at redhat dot com
Subject: [Bug crypto/27849] New: getIV() call on cipher for DESede/CBC returns null
Date: 31 May 2006 22:14:08 -0000

Cipher.getIV() should return the IV for DESede/CBC, but returns null. The test
case below demonstrates this bug. The same code when run under bouncycastle
returns a non-null byte array while our implementation returns null.

import gnu.javax.crypto.jce.GnuCrypto;

import javax.crypto.Cipher;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.InvalidAlgorithmParameterException;
import java.security.Key;
import java.security.InvalidKeyException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Iterator;
import java.util.Set;

public class Test {
        // Switch the provider name here to BC when trying with bouncycastle
        private static final String PN = "GNU-CRYPTO";

        private static String algorithm = "DESede";

        private static String transformation = "DESede/CBC/PKCS7Padding";

        private static Key key = null;

        private static Cipher cipher = null;

        private static void setUp() throws Exception {
                Security.addProvider(new BouncyCastleProvider());
                Security.addProvider(new GnuCrypto());

                Provider[] arr = Security.getProviders();

                for (int i = 0; i < arr.length; i++) {

                Set keys = Security.getProvider(PN).keySet();

                KeyGenerator keyG = KeyGenerator.getInstance(algorithm, PN);
                cipher = Cipher.getInstance(transformation, PN);

                keyG.init(new SecureRandom());
                key = keyG.generateKey();
                System.out.println("Provider being used is: " +


        public static void main(String[] args) throws Exception {

                byte[] encryptionBytes = null;
                String input = "Does this work?";
                System.out.println("Entered: " + input);
                encryptionBytes = encrypt(input);
                System.out.println("Recovered: " + decrypt(encryptionBytes));

        private static byte[] encrypt(String input) throws InvalidKeyException,
                        BadPaddingException, IllegalBlockSizeException {
                cipher.init(Cipher.ENCRYPT_MODE, key);
                System.out.println("IV size for the cipher is: " +
                byte[] inputBytes = input.getBytes();
                return cipher.doFinal(inputBytes);

        private static String decrypt(byte[] encryptionBytes)
                        throws InvalidKeyException, BadPaddingException,
InvalidAlgorithmParameterException {
                cipher.init(Cipher.DECRYPT_MODE, key, cipher.getParameters());
                 System.out.println("IV size for the cipher is: " +
                byte[] recoveredBytes = cipher.doFinal(encryptionBytes);
                String recovered = new String(recoveredBytes);
                return recovered;

           Summary: getIV() call on cipher for DESede/CBC returns null
           Product: classpath
           Version: 0.92
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: crypto
        AssignedTo: csm at gnu dot org
        ReportedBy: vivekl at redhat dot com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]