Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Fix bug decryptor "RNCryptorError error 2" in ios, when encryptor in Android #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions rncryptor-native/src/main/jni/rncryptor-native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ jbyteArray Java_tgio_rncryptor_RNCryptorNative_encrypt(JNIEnv *env, jobject inst
}


jstring Java_tgio_rncryptor_RNCryptorNative_decrypt(JNIEnv *env, jobject instance, jstring encrypted_, jstring password_) {
string decrypted = "0";
jbyteArray Java_tgio_rncryptor_RNCryptorNative_decrypt(JNIEnv *env, jobject instance,
jstring encrypted_, jstring password_) {
std::string decrypted;
if (encrypted_ != NULL) {
try {
const char *encrypted = env->GetStringUTFChars(encrypted_, 0);
Expand All @@ -95,9 +96,12 @@ jstring Java_tgio_rncryptor_RNCryptorNative_decrypt(JNIEnv *env, jobject instanc
delete cryptor;
env->ReleaseStringUTFChars(encrypted_, encrypted);
env->ReleaseStringUTFChars(password_, password);
jbyteArray array = env->NewByteArray((jsize) decrypted.size());
env->SetByteArrayRegion(array, 0, (jsize) decrypted.size(), (const jbyte *) decrypted.c_str());
return array;
} catch (exception e) {
decrypted = "error decrypting";
}
}
return env->NewStringUTF(decrypted.c_str());
return NULL;
}
2 changes: 1 addition & 1 deletion rncryptor-native/src/main/jni/rncryptor-native.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {
#endif
JNIEXPORT jstring JNICALL Java_tgio_rncryptor_RNCryptorNative_getABI(JNIEnv* env, jobject thiz);
JNIEXPORT jbyteArray JNICALL Java_tgio_rncryptor_RNCryptorNative_encrypt(JNIEnv *env, jobject instance, jstring raw_, jstring password_);
JNIEXPORT jstring JNICALL Java_tgio_rncryptor_RNCryptorNative_decrypt(JNIEnv *env, jobject instance, jstring encrypted_, jstring password_);
JNIEXPORT jbyteArray JNICALL Java_tgio_rncryptor_RNCryptorNative_decrypt(JNIEnv *env, jobject instance, jstring encrypted_, jstring password_);
#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion rncryptor-native/src/main/jni/rncryptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using CryptoPP::Base64Encoder;
using CryptoPP::Base64Decoder;

RNCryptor::RNCryptor() {
configureSettings(SCHEMA_2);
configureSettings(SCHEMA_3);
}

void RNCryptor::configureSettings(RNCryptorSchema schemaVersion)
Expand All @@ -59,6 +59,7 @@ void RNCryptor::configureSettings(RNCryptorSchema schemaVersion)
break;

case SCHEMA_2:
case SCHEMA_3:
aesMode = MODE_CBC;
options = OPTIONS_1;
hmac_includesHeader = true;
Expand Down
2 changes: 1 addition & 1 deletion rncryptor-native/src/main/jni/rncryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum RNCryptorAlgorithm {
};

enum RNCryptorSchema {
SCHEMA_0, SCHEMA_1, SCHEMA_2
SCHEMA_0, SCHEMA_1, SCHEMA_2, SCHEMA_3
};

enum RNCryptorOptions {
Expand Down
2 changes: 1 addition & 1 deletion rncryptor-native/src/main/jni/rnencryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RNEncryptor : public RNCryptor {
string generateSalt();

public:
string encrypt(string plaintext, string password, RNCryptorSchema schemaVersion = SCHEMA_2);
string encrypt(string plaintext, string password, RNCryptorSchema schemaVersion = SCHEMA_3);
};

#endif