13 nov 12.30 pm

Dependencies:   mbed-rtos mbed wolfSSL

Files at this revision

API Documentation at this revision

Comitter:
preyaa4
Date:
Tue Nov 13 07:06:14 2018 +0000
Commit message:
13 nov 12.30 pm

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
wolfSSL.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1c8dabfe6522 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 13 07:06:14 2018 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+
+#include <iostream>
+#include <string.h>
+#include <wolfssl/openssl/rsa.h>
+#include <wolfssl/openssl/pem.h>
+#include <wolfssl/openssl/err.h>
+
+#include "openssl_rsa.h"
+
+
+using namespace std;
+
+
+int main() {
+    
+    LOG("OpenSSL_RSA has been started.");
+    
+    RSA *private_key;
+    RSA *public_key;
+
+    char message[KEY_LENGTH / 8] = "Batuhan AVLAYAN - OpenSSL_RSA demo";
+    char *encrypt = NULL;
+    char *decrypt = NULL;
+
+    char private_key_pem[12] = "private_key";
+    char public_key_pem[11]  = "public_key";
+
+    LOG(KEY_LENGTH);
+    LOG(PUBLIC_EXPONENT);
+    
+    RSA *keypair = RSA_generate_key(KEY_LENGTH, PUBLIC_EXPONENT, NULL, NULL);
+    LOG("Generate key has been created.");
+
+    private_key = create_RSA(keypair, PRIVATE_KEY_PEM, private_key_pem);
+    LOG("Private key pem file has been created.");
+
+    public_key  = create_RSA(keypair, PUBLIC_KEY_PEM, public_key_pem);
+    LOG("Public key pem file has been created.");;
+
+    encrypt = (char*)malloc(RSA_size(public_key));
+    int encrypt_length = public_encrypt(strlen(message) + 1, (unsigned char*)message, (unsigned char*)encrypt, public_key, RSA_PKCS1_OAEP_PADDING);
+    if(encrypt_length == -1) {
+        LOG("An error occurred in public_encrypt() method");
+    }
+    LOG("Data has been encrypted.");
+
+    create_encrypted_file(encrypt, public_key);
+    LOG("Encrypted file has been created.");
+
+    decrypt = (char *)malloc(encrypt_length);
+    int decrypt_length = private_decrypt(encrypt_length, (unsigned char*)encrypt, (unsigned char*)decrypt, private_key, RSA_PKCS1_OAEP_PADDING);
+    if(decrypt_length == -1) {
+        LOG("An error occurred in private_decrypt() method");
+    }
+    LOG("Data has been decrypted.");
+
+    FILE *decrypted_file = fopen("decrypted_file.txt", "w");
+    fwrite(decrypt, sizeof(*decrypt), decrypt_length - 1, decrypted_file);
+    fclose(decrypted_file);
+    LOG("Decrypted file has been created.");
+    
+    RSA_free(keypair);
+    free(private_key);
+    free(public_key);
+    free(encrypt);
+    free(decrypt);
+    LOG("OpenSSL_RSA has been finished.");
+
+    return 0;
+}
\ No newline at end of file
diff -r 000000000000 -r 1c8dabfe6522 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Nov 13 07:06:14 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/mbed-rtos/#83895f30f8f2
diff -r 000000000000 -r 1c8dabfe6522 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 13 07:06:14 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file
diff -r 000000000000 -r 1c8dabfe6522 wolfSSL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wolfSSL.lib	Tue Nov 13 07:06:14 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/wolfSSL/code/wolfSSL/#117db924cf7c