-
Notifications
You must be signed in to change notification settings - Fork 39
/
hidingutil.c
58 lines (41 loc) · 1.66 KB
/
hidingutil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <string.h>
#include <jni.h>
#include "Base64Util.h"
#include <android/log.h>
static unsigned char passwordKey[] = "My_S3cr3t_P@$$W0rD";
void xor_value_with_key(const char* value, char* xorOutput){
int i = 0;
while(value[i] != '\0'){
int offset = i % sizeof(passwordKey);
xorOutput[i] = value[i] ^ passwordKey[offset];
i++;
}
}
/**
* com.apothesource.hidingpasswords.HidingUtil.hide
*
* This function uses a hard-coded password to XOR hide (encrypt) a provided message.
*/
jstring Java_com_apothesource_hidingpasswords_HidingUtil_hide(JNIEnv* env, jobject thiz, jstring javaString) {
const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
char xorOutput[BUFFFERLEN + 1] = "";
xor_value_with_key(nativeString, xorOutput);
char encodedoutput[BUFFFERLEN + 1] = "";
Base64Encode(xorOutput, encodedoutput, BUFFFERLEN);
(*env)->ReleaseStringUTFChars(env, javaString, nativeString);
return (*env)->NewStringUTF(env, encodedoutput);
}
/**
* com.apothesource.hidingpasswords.HidingUtil.unhide
*
* This function uses a hard-coded password to XOR unhide (decrypt) a provided message.
*/
jstring Java_com_apothesource_hidingpasswords_HidingUtil_unhide(JNIEnv* env, jobject thiz, jstring javaString) {
const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
char decodedoutput[BUFFFERLEN + 1] = "";
Base64Decode(nativeString, decodedoutput, BUFFFERLEN);
char xorOutput[BUFFFERLEN + 1] = "";
xor_value_with_key(decodedoutput, xorOutput);
(*env)->ReleaseStringUTFChars(env, javaString, nativeString);
return (*env)->NewStringUTF(env, xorOutput);
}