Android 如何编写Cipher.getInstance(“DES”);在jni?

Android 如何编写Cipher.getInstance(“DES”);在jni?,android,java-native-interface,Android,Java Native Interface,我想换衣服 Cipher cipher = Cipher.getInstance("DES"); 进入jni中的cpp代码。如何做 JNIEnv *jni; //Comes from somewhere jclass cl = jni->FindClass("javax/crypto/Cipher"); jmethodID MID = jni->GetStaticMethodID(cl, "getInstance", "(Ljava/lang/String)Ljavax/cryp

我想换衣服

Cipher cipher = Cipher.getInstance("DES"); 
进入jni中的cpp代码。如何做

JNIEnv *jni; //Comes from somewhere
jclass cl = jni->FindClass("javax/crypto/Cipher");
jmethodID MID = jni->GetStaticMethodID(cl, "getInstance", "(Ljava/lang/String)Ljavax/crypto/Cipher;");
jstring s = jni->NewStringUTF("DES");
jobject cipher = jni->CallStaticObjectMethod(cl, MID, s);

这省略了错误处理。

另一种选择是使用本机代码进行加密,例如OpenSSL


强制性警告:不要使用DES

多谢各位!我犯了一个错误,我将CallStaticObjectMethod(cl,MID,s)写入CallObjectMethod(cl,MID,s)。因为a键非常短,可以在一天内强制输入。此外,还有更有效的攻击。