Hey guys i'm having trouble with a jni interface to OpenSSL. 

This is my Java:


public class nativeBF {

        public native void nativeRun();
        
        public void nCall(){
                
                nativeRun();
        }

        static {
                
            //Load the shared library
            System.loadLibrary ( "nativebf" ) ;

      }

}

This is my C. (I took this from a post somewhere here on OpenSSL

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Old version = /usr/local/ .. /include/blowfish.h.  
#include <openssl/blowfish.h>

void decrypt(char *inbuf, char *outbuf, int blklen, char *key)
{
  int counter = 0;
  char iv[8];
  BF_KEY keyStruct;

  memset(iv, 0, 8);
  BF_set_key(&keyStruct, strlen(key), key);
  BF_cfb64_encrypt(inbuf, outbuf, blklen, &keyStruct, iv, &counter,
BF_DECRYPT);

}

void encrypt(char *inbuf, char *outbuf, int blklen, char *key)
{
  int counter = 0;
  char iv[8];
  BF_KEY keyStruct;

  memset(iv, 0, 8);
  BF_set_key(&keyStruct, strlen(key), key);
  BF_cfb64_encrypt(inbuf, outbuf, blklen, &keyStruct, iv, &counter,
BF_ENCRYPT);

}

JNIEXPORT void JNICALL 
Java_nativeBF_nativeRun(JNIEnv* env, jobject thisObj){ 
//Manually add env and thisObj (javah bug ? )

  char *plain, *key1, *key2;
  char *enc;
  char *dec;
  int len;

  txtToEncrypt = "Testing 1"; //What to encrypt
  len = strlen(txtToEncrypt); 
  key1 = "key"; 
  key2 = "keykey";

  enc = malloc(len+1); //cipher routines 
  enc[len] = '\0';
  dec = malloc(len+1); 
  dec[len] = '\0';

  encrypt(txtToEncrypt, enc, len, key1); //Encrypt txtToEncryptt using
enc with key1
  decrypt(enc, dec, len, key2);  //Decrypt enc(txtToEncrypt) using key2

}

And this is my header file.

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class nativeBF */

#ifndef _Included_nativeBF
#define _Included_nativeBF
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     nativeBF
 * Method:    nativeRun
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_nativeBF_nativeRun
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif


This is the error generated. 

java nativeBF
Exception in thread "main"
java.lang.UnsatisfiedLinkError: 
/home/mcx/Programming/Eclipse/project/lib/libnativebf.so: 
/home/mcx/Programming/Eclipse/project/lib/libnativebf.so: undefined symbol: 
BF_set_key
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511)
        at java.lang.Runtime.loadLibrary0(Runtime.java:788)
        at java.lang.System.loadLibrary(System.java:834)
        at nativeBF.<clinit>(nativeBF.java:13)

Can anyone please shed some light on this ? Its much appreciated. 

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to