From fbdd24d9ecfa32396bd1ae0130662de26f8d5ee4 Mon Sep 17 00:00:00 2001 From: wuriyanto Date: Sun, 3 Sep 2023 17:39:32 +0700 Subject: [PATCH] update readme --- Main.cpp | 26 ------------- README.md | 60 ++++++++++++++++++++++++++++- main.c | 113 ------------------------------------------------------ 3 files changed, 59 insertions(+), 140 deletions(-) delete mode 100644 Main.cpp delete mode 100644 main.c diff --git a/Main.cpp b/Main.cpp deleted file mode 100644 index 9391383..0000000 --- a/Main.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "crypsi.h" - -int main(int argc, char** argv) -{ - - const char* message = "wuriyanto"; - - unsigned char* dst_digest; - unsigned int dst_digets_len; - - if(crypsi_sha512((const unsigned char*) message, strlen(message), &dst_digest, &dst_digets_len) != 0) { - printf("digest error\n"); - return -1; - } - - printf("message len: %d\n", dst_digets_len); - - printf("digest result: %s\n", dst_digest); - - printf("__cplusplus: %ld\n", __cplusplus); - - delete dst_digest; - - return 0; -} \ No newline at end of file diff --git a/README.md b/README.md index 0dcc7e4..796df4a 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,62 @@ todo - Generate Hash with Common DIGEST Algorithm ✔️ #### Example -todo +C +```c +#include +#include +#include +#include "crypsi.h" + +int main(int argc, char** argv) { + printf("hello\n"); + + char* message = "wuriyanto"; + + unsigned char* dst_digest; + int dst_digets_len; + + if(crypsi_sha512(message, strlen(message), &dst_digest, &dst_digets_len) != 0) { + printf("digest error\n"); + return -1; + } + + printf("message len: %d\n", dst_digets_len); + + printf("digest result: %s\n", dst_digest); + + free((void*) dst_digest); + + return 0; +} +``` + +C++ +```CPP +#include +#include "crypsi.h" + +int main(int argc, char** argv) +{ + + const char* message = "wuriyanto"; + + unsigned char* dst_digest; + unsigned int dst_digets_len; + + if(crypsi_sha512((const unsigned char*) message, strlen(message), &dst_digest, &dst_digets_len) != 0) { + printf("digest error\n"); + return -1; + } + + printf("message len: %d\n", dst_digets_len); + + printf("digest result: %s\n", dst_digest); + + printf("__cplusplus: %ld\n", __cplusplus); + + delete dst_digest; + + return 0; +} +``` \ No newline at end of file diff --git a/main.c b/main.c deleted file mode 100644 index ee1b4a0..0000000 --- a/main.c +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include -#include "crypsi.h" - -int main(int argc, char** argv) { - printf("hello\n"); - - char* message = "wuriyanto"; - - unsigned char* dst_digest; - int dst_digets_len; - - if(crypsi_sha512(message, strlen(message), &dst_digest, &dst_digets_len) != 0) { - printf("digest error\n"); - return -1; - } - - printf("message len: %d\n", dst_digets_len); - - printf("digest result: %s\n", dst_digest); - - free((void*) dst_digest); - - // -------------------------------------------------------------------------- - - // unsigned char* dst_encode; - // int dst_encode_len; - - // unsigned char* dst_decode; - // int dst_decode_len; - - // if(hexencode(message, strlen(message), &dst_encode, &dst_encode_len) != 0) { - // printf("hexencode error\n"); - // return -1; - // } - - // printf("message len: %d\n", dst_encode_len); - - // printf("hex result: %s\n", dst_encode); - - // if(hexdecode(dst_encode, dst_encode_len, &dst_decode, &dst_decode_len) != 0) { - // printf("hexdecode error\n"); - // return -1; - // } - - // printf("message len: %d\n", dst_decode_len); - - // printf("hex result: %s\n", dst_decode); - - // free((void*) dst_encode); - // free((void*) dst_decode); - - // ----------------------------------------- - unsigned char key_128[17] = "abc$#128djdyAgbj"; - key_128[sizeof(key_128)-1] = 0x0; - - unsigned char key_192[25] = "abc$#128djdyAgbjau&YAnmc"; - key_192[sizeof(key_192)-1] = 0x0; - - unsigned char key_256[33] = "abc$#128djdyAgbjau&YAnmcbagryt5x"; - key_256[sizeof(key_256)-1] = 0x0; - - unsigned char* plain_data = "wuriyanto"; - - unsigned char* dst; - int dst_len; - - if(crypsi_aes_128_gcm_encrypt(key_128, plain_data, strlen(plain_data), &dst, &dst_len) != 0) { - printf("encrypt with aes error\n"); - return -1; - } - - printf("encrypt result: %s\n", dst); - printf("encrypt result len: %d\n", dst_len); - - printf("-----------------------------------------\n"); - - unsigned char* dst_decrypt; - int dst_decrypt_len; - - if(crypsi_aes_128_gcm_decrypt(key_128, "28f23b5b307e0fdd2003dd0afc5ac9d26632437ff543e9e4947ff69f385e16541724f06baa830fdb", strlen("28f23b5b307e0fdd2003dd0afc5ac9d26632437ff543e9e4947ff69f385e16541724f06baa830fdb"), &dst_decrypt, &dst_decrypt_len) != 0) { - printf("decrypt with aes error\n"); - return -1; - } - - printf("decrypt result: %s\n", dst_decrypt); - printf("decrypt result len: %ld\n", strlen(dst_decrypt)); - printf("decrypt result len: %d\n", dst_decrypt_len); - - - free((void*) dst_decrypt); - free((void*) dst); - - // hmac -------------------------------------------- - char* message_hmac = "wuriyanto"; - - unsigned char* dst_digest_hmac; - int dst_digets_len_hmac; - - if(crypsi_hmac_sha256(key_256, message, strlen(message), &dst_digest_hmac, &dst_digets_len_hmac) != 0) { - printf("hmac error\n"); - return -1; - } - - printf("hmac message len: %d\n", dst_digets_len_hmac); - - printf("hmac result: %s\n", dst_digest_hmac); - - free((void*) dst_digest_hmac); - - return 0; -} \ No newline at end of file