1
我想從C/C++代碼生成JNI包裝。SWIG生成的Android上的JNI代碼問題
這是我的接口文件。
/* aes_security.i */
%module jni_security_example
%{
#include "pbkdf2.h"
%}
extern int pbkdf2_sha1 (const char *passphrase, size_t passphraseLength,
const char *SSID, size_t SSIDlen,
unsigned int iterationCount,
char *aeskey, size_t keyLength);
extern int GenrateIV_16_Bytes(unsigned char *IV);
以下是SWIG生成的Java代碼片斷
public static int pbkdf2_sha1(String passphrase, long passphraseLength,
String SSID, long SSIDlen, long encryptGrade, String key,
long keyLength) {
return cot_jni_security_exampleJNI.pbkdf2_sha1(passphrase,
passphraseLength, SSID, SSIDlen, encryptGrade, key, keyLength);
}
public static int GenrateIV_16_Bytes(SWIGTYPE_p_unsigned_char IV) {
return cot_jni_security_exampleJNI
.GenrateIV_16_Bytes(SWIGTYPE_p_unsigned_char.getCPtr(IV));
}
這裏是我如何調用JNI代碼。
private String PASSPHRASE = "password";
private String SSID = "dummyssid";
private long iterationCount = 4096;
public String pbkdf2SHA1() {
int keyLength = 32;
char[] aesKey = new char[keyLength];
int result = pbkdf2_sha1(PASSPHRASE, (long) PASSPHRASE.length(), SSID,
SSID.length(), iterationCount, aesKey.toString(),
(long) keyLength);
Log.e(TAG, "Result " + result);
return new String(aesKey);
}
該代碼編譯,但是當我運行它崩潰在C代碼的某處。任何幫助將不勝感激。
謝謝。