-
OpenSSL을 이용한 Triple-DES cbc mode 구현하기/Visual C++ 6.0컴퓨터+a/설치, 오류 2018. 6. 5. 11:38
1. OpenSSL 다운로드
https://slproweb.com/products/Win32OpenSSL.html
컴퓨터가 64bit이더라도 Visual c++에서 windows console 32로 코딩하므로 32bit 설치할 것
기본 디렉토리 C:\OpenSSL-Win32
2. Tools - Option - Directories
Show directories for : Include files에 추가 - C:\OpenSSL-Win32\include
Library files에 추가 - C:\OpenSSL-Win32\lib\VC
3. Project - Setting - Link
Object/library modules에 추가 - libcrypto32MD.lib libcrypto32MDd.lib libcrypto32MT.lib libcrypto32MTd.lib libssl32MD.lib libssl32MDd.lib libssl32MT.lib libssl32MTd.lib
4. 예제 코드
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#include <stdio.h>#include <stdlib.h>#include <string.h>#include <openssl/des.h>/* Triple DES key for Encryption and Decryption */DES_cblock Key1 = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };DES_cblock Key2 = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 };DES_cblock Key3 = { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33 };DES_key_schedule SchKey1,SchKey2,SchKey3;/* Print Encrypted and Decrypted data packets */void print_data(const char *tittle, const void* data, int len);int main(){/* Input data to encrypt */unsigned char input_data[] = {0x01, 0x02, 0x03, 0x04, 0x05};/* Init vector */DES_cblock iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };DES_set_odd_parity(&iv);/* Check for Weak key generation */if ( -2 == (DES_set_key_checked(&Key1, &SchKey1) || DES_set_key_checked(&Key2, &SchKey2) || DES_set_key_checked(&Key3, &SchKey3))){printf(" Weak key ....\n");return 1;}/* Buffers for Encryption and Decryption */unsigned char* cipher[sizeof(input_data)];unsigned char* text[sizeof(input_data)];/* Triple-DES CBC Encryption */DES_ede3_cbc_encrypt( (unsigned char*)input_data, (unsigned char*)cipher, sizeof(input_data), &SchKey1, &SchKey2, &SchKey3,&iv, DES_ENCRYPT);/* Triple-DES CBC Decryption */memset(iv,0,sizeof(DES_cblock)); // You need to start with the same iv valueDES_set_odd_parity(&iv);DES_ede3_cbc_encrypt( (unsigned char*)cipher, (unsigned char*)text, sizeof(input_data), &SchKey1, &SchKey2, &SchKey3,&iv,DES_DECRYPT);/* Printing and Verifying */print_data("\n Original ",input_data,sizeof(input_data));print_data("\n Encrypted",cipher,sizeof(input_data));print_data("\n Decrypted",text,sizeof(input_data));return 0;}void print_data(const char *tittle, const void* data, int len){printf("%s : ",tittle);const unsigned char * p = (const unsigned char*)data;int i = 0;for (; i<len;++i)printf("%02X ", *p++);printf("\n");}cs 728x90'컴퓨터+a > 설치, 오류' 카테고리의 다른 글
아두이노 No such file or directory 'header' : 라이브러리 포함하기 (0) 2020.04.19 아두이노 IDE 설치, Arduino IDE Download, 아두이노 개발 환경 구축 (0) 2020.04.19 윈도우 업데이트 후 생성된 로컬드라이브 없애는 법 (2) 2018.05.13 Mysql 에러 : ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) (3) 2018.05.10 리눅스, 라즈베리파이 QT 한글 (0) 2018.01.10