WA-SDK  3.0.4.0
WA-SDK
wasdk/sample_wasdk_symmetric_encryption.c
#include <stdio.h>
#include "wasdk_public.h"
static int sample_setup() {
EErrorCode result = wasdk_init();
if (result != EEC_Success) {
printf("[ERROR] %s\n", wasdk_error_message(result));
return 1;
}
return 0;
}
static int sample_wasdk_symmetric_encryption() {
EErrorCode result;
const unsigned char plaintext[] = { 'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','t','e','x','t' };
unsigned char secretKey[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
};
unsigned char encrypted[16 * ((sizeof(plaintext) / 16) + 1)] = { 0, };
int encryptedSize = 0;
unsigned char decrypted[sizeof(encrypted)] = { 0, }; // 버퍼의 크기는 암호문의 크기. 원문의 크기가 아닌 것에 유의할 것.
int decryptedSize = 0;
printf("sample_wasdk_symmetric_encryption() => ");
result = wasdk_symmetric_encrypt(encrypted, &encryptedSize, sizeof(encrypted), plaintext, sizeof(plaintext),
secretKey, 16, NULL, 0, ESA_SEED, ESOM_CBC);
if (result != EEC_Success) {
printf("[ERROR] %s\n", wasdk_error_message(result));
return 1;
}
result = wasdk_symmetric_decrypt(decrypted, &decryptedSize, sizeof(decrypted), encrypted, encryptedSize,
secretKey, 16, NULL, 0, ESA_SEED, ESOM_CBC);
if (result != EEC_Success) {
printf("[ERROR] %s\n", wasdk_error_message(result));
return 1;
}
printf("[OK]\n");
return 0;
}
int main() {
int result;
result = sample_setup();
if (result != 0) {
return result;
}
return sample_wasdk_symmetric_encryption();
}
EErrorCode
새롭게 구현된 내부 API 에서 사용되는 에러코드들
Definition: wasdk_errorcode.h:13
@ EEC_Success
성공
Definition: wasdk_errorcode.h:14
WA_SDK_API const char *FUNCCALL wasdk_error_message(EErrorCode errorCode)
에러코드에 해당하는 에러 메시지를 가져온다.
WA_SDK_API EErrorCode FUNCCALL wasdk_init(void)
모듈 초기화를 실행한다.
WA_SDK_API EErrorCode FUNCCALL wasdk_symmetric_encrypt(unsigned char *encrypted, int *encryptedSize, int encryptedBufSize, const unsigned char *plaintext, int plaintextSize, const unsigned char *key, int keySize, const unsigned char *iv, int ivSize, ESymmetricAlgorithm symmAlg, ESymmetricOperationMode opMode)
비밀키 암호화를 실행한다.
WA_SDK_API EErrorCode FUNCCALL wasdk_symmetric_decrypt(unsigned char *decrypted, int *decryptedSize, int decryptedBufSize, const unsigned char *encrypted, int encryptedSize, const unsigned char *key, int keySize, const unsigned char *iv, int ivSize, ESymmetricAlgorithm symmAlg, ESymmetricOperationMode opMode)
비밀키 복호화를 실행한다.
@ ESA_SEED
SEED
Definition: wasdk_public.h:66
@ ESOM_CBC
CBC (Cipher Block Chaining)
Definition: wasdk_public.h:49