Last active
October 9, 2023 06:42
-
-
Save maxenko/fd5c0287d44c44e68f4ff9d37cb3d83c to your computer and use it in GitHub Desktop.
Revisions
-
Max Enko renamed this gist
Apr 30, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Max Enko revised this gist
Apr 30, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,9 +18,9 @@ int main() unsigned char mr_pk[crypto_box_PUBLICKEYBYTES]; // public key unsigned char mr_sk[crypto_box_SECRETKEYBYTES]; // private key crypto_box_keypair(mr_pk, mr_sk); // generates random key pair unsigned char ciphertext[CIPHERTEXT_LEN]; // encrypted msg crypto_box_seal(ciphertext, MESSAGE, MESSAGE_LEN, mr_pk); // encrypt /* -
Max Enko revised this gist
Apr 30, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,6 @@ using namespace std; #define CIPHERTEXT_LEN (crypto_box_SEALBYTES + MESSAGE_LEN) int main() { if (sodium_init() < 0) { @@ -34,8 +33,9 @@ int main() unsigned char decrypted[CIPHERTEXT_LEN - crypto_box_SEALBYTES + 1]; auto decr_msg = crypto_box_seal_open(decrypted, ciphertext, CIPHERTEXT_LEN, mr_pk, mr_sk); // decrypt cout << (decr_msg == 0 ? "Success \n" : "Failure \n"); if (decr_msg == 0) { decrypted[CIPHERTEXT_LEN - crypto_box_SEALBYTES] = 0; cout << "Decrypted: " << decrypted; } -
Max Enko created this gist
Apr 30, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ //#include "stdafx.h" #include <sodium.h> #include <iostream> using namespace std; #define MESSAGE (const unsigned char *) "test" #define MESSAGE_LEN 4 #define CIPHERTEXT_LEN (crypto_box_SEALBYTES + MESSAGE_LEN) int main() { if (sodium_init() < 0) { cout << "sodium cannot initialize, exiting..."; return 1; } unsigned char mr_pk[crypto_box_PUBLICKEYBYTES]; // public key unsigned char mr_sk[crypto_box_SECRETKEYBYTES]; // private key crypto_box_keypair(mr_pk, mr_sk); // generates random key pair unsigned char ciphertext[CIPHERTEXT_LEN]; // encrypted msg crypto_box_seal(ciphertext, MESSAGE, MESSAGE_LEN, mr_pk); // encrypt /* unsigned char encrypted_display[CIPHERTEXT_LEN+1]; memcpy(encrypted_display, ciphertext, CIPHERTEXT_LEN); encrypted_display[CIPHERTEXT_LEN] = 0; cout << "encrypted: " << encrypted_display << "\n"; */ unsigned char decrypted[CIPHERTEXT_LEN - crypto_box_SEALBYTES + 1]; auto decr_msg = crypto_box_seal_open(decrypted, ciphertext, CIPHERTEXT_LEN, mr_pk, mr_sk); // decrypt if (decr_msg == 0) { cout << (decr_msg == 0 ? "Success \n" : "Failure \n"); decrypted[CIPHERTEXT_LEN - crypto_box_SEALBYTES] = 0; cout << "Decrypted: " << decrypted; } return 0; }