-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathumamicrypt.c
63 lines (48 loc) · 1.41 KB
/
umamicrypt.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
58
59
60
61
62
63
#include "umamicrypt.h"
int Encode(char **dest, char *plaintext, unsigned char *key, unsigned char *iv)
{
/* Bytes to be encrypted */
//unsigned char *plaintext = (unsigned char *)input;
/* Buffer for ciphertext. Ensure the buffer is long enough for the
* ciphertext which may be longer than the plaintext, dependant on the
* algorithm and mode
*/
unsigned char ciphertext[10000];
int ciphertext_len;
/* Initialise the library */
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();
OPENSSL_config(NULL);
int textlen = strlen(plaintext);
/* Encrypt the plaintext */
ciphertext_len = encrypt((unsigned char *)plaintext, textlen, key, iv, ciphertext);
printf("Ciphertext length is: %d\n", ciphertext_len);
int counter;
printf("Dumping Original String\n");
printf("%s\n",plaintext);
printf("\n");
printf("Dumping Original Bytes\n");
for (counter=0; counter < textlen; counter++)
{
printf("\\x%02x",plaintext[counter]);
}
printf("\n");
printf("\n");
printf("Dumping AES Encrypted Bytes\n");
for (counter=0; counter < ciphertext_len; counter++)
{
printf("\\x%02x",ciphertext[counter]);
}
printf("\n");
printf("\n");
//char* base64EncodeOutput;
int length;
printf("Encoding: Ciphertext\n");
length = Base64Encode(dest, ciphertext, ciphertext_len);
printf("%s\n", *dest);
printf("\n");
/* Clean up */
EVP_cleanup();
ERR_free_strings();
return length;
}