gnu-crypto-discuss
[Top][All Lists]
Advanced

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

[GNU Crypto] Problem when running crypto


From: bparker
Subject: [GNU Crypto] Problem when running crypto
Date: Tue, 15 Mar 2005 10:30:07 -0500


I have been getting the following error when running a small sample program to test out using gnu crypto. No matter what algorithm I try, even AES by itself, I get the same results. Any insight on what I am doing wrong will be greatly appreciated.

Exception in getMainCipher
java.security.NoSuchAlgorithmException: AES/CFB/NoPadding not found
   at javax.crypto.Cipher.getInstance(java.lang.String) (/home/acuser/gcj/crypt/javax-crypto.so)
   at cryptTester2.getMainCipher() (Unknown Source)
   at cryptTester2.main(java.lang.String[]) (Unknown Source)
   at gnu.java.lang.MainThread.call_main() (/usr/local/lib/libgcj.so.6.0.0)
   at gnu.java.lang.MainThread.run() (/usr/local/lib/libgcj.so.6.0.0)

I have built the three shared libraries javax-crypto, javax-security and gnu-crypto from the jar files.

I have successfully compiled and ran my sample program using the sdk ee.

My build script looks like this:

gcj -O2 -shared -findirect-dispatch javax-crypto.jar -o javax-crypto.so

gcj -O2 -shared  -findirect-dispatch javax-security.jar -o javax-security.so

gcj -O2 -shared -findirect-dispatch gnu-crypto.jar -o gnu-crypto.so

gcj -o crypto -O2 --classpath=/home/acuser/gcj/crypt/javax-security.jar:/home/acuser/gcj/crypt/gnu-crypto.jar:/home/acuser/gcj/crypt/javax-crypto.jar cryptTester2.java --main=cryptTester2  /home/acuser/gcj/crypt/javax-security.so /home/acuser/gcj/crypt/gnu-crypto.so /home/acuser/gcj/crypt/javax-crypto.so -L /usr/local/lib -lgcj

My source code looks like this:

import java.security.NoSuchAlgorithmException;
import javax.security.*;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;

public class cryptTester2
{
        private static Cipher mCipher, sCipher;
        private static byte[] activationCipher = new byte[] {92, 111, 8, 30, -50, 17, 48, -79, 1, 90, 45, 2, -50, -100, -79, 82 };
        private static byte[] activationIV = new byte[] {79, -32, -69, -29, -47, -24, -97, 91, 1, -122, -64, -125, 73, -116, 0, -99 };
        private static SecretKeySpec mainSkeySpec = new SecretKeySpec(activationCipher, "AES");
        private static IvParameterSpec ivParmSpec = new IvParameterSpec(activationIV);                

        public static void main(String[] args)
        {
                int exitCode = 0;

                try
                {
                        byte[] testcrypto = new byte[16];
                        String testValue = "1234567890123456";
                        testcrypto = testValue.getBytes();
                       
                        System.out.println("Value before encrypting = " + testValue);
               

                        /*
                        **  encrypt
                        */
                        byte[] e16 = new byte[16];
                        System.arraycopy(testcrypto, 0, e16, 0, 16);
               
                        getMainCipher().init(Cipher.ENCRYPT_MODE, mainSkeySpec, ivParmSpec);                        
                        byte[] bDecode = getMainCipher().doFinal(e16);
                       
                                                               
                        /*
                        **  decrypt
                        */

                        byte[] d16 = new byte[16];
                        System.arraycopy(bDecode, 0, d16, 0, bDecode.length);
                                               
                        getMainCipher().init(Cipher.DECRYPT_MODE, mainSkeySpec, ivParmSpec);                        
                        byte[] bAES = getMainCipher().doFinal(d16);                        

                        String hootie = new String (bAES);
                        System.out.println("Value after decryption = " + hootie);        
                                               
                }
                catch (Exception x)
                {
                        System.out.println("exception code = " + x);
                }
               
                System.exit(exitCode);
               
        }

       
        private static Cipher getMainCipher()
        {
       
                if (mCipher==null)
       
                try
                {
                        mCipher = Cipher.getInstance("AES/CFB/NoPadding");

        //                mCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");


                        return mCipher;
                }
                catch (NoSuchAlgorithmException e)        
                {
                        System.out.println("Exception in getMainCipher");
                        e.printStackTrace();

                } catch (NoSuchPaddingException e)
                {
                        e.printStackTrace();
                }
                return mCipher;
        }
       
}


reply via email to

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