WA-SDK  3.0.4.0
WA-SDK
issacweb/sample_issacweb_symmetric_encryption.c
#include <stdio.h>
#include "issacweb.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_issacweb_symmetric_encryption() {
const unsigned char plaintext[] = {
0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10,
0x00, 0xF0, 0xE0, 0xD0, 0xC0, 0xB0, 0xA0, 0x90
};
unsigned char secretKey[] = {
0x7B, 0xAA, 0x7D, 0x69, 0xAC, 0xE6, 0x52, 0xA0,
0xD2, 0x1C, 0x16, 0x92, 0xAD, 0x91, 0x04, 0x1E
};
unsigned char encrypted[16 * ((sizeof(plaintext) / 16) + 1)] = { 0, };
int encryptedLen = 0;
unsigned char decrypted[sizeof(encrypted)] = { 0, }; // 버퍼의 크기는 암호문의 크기. 원문의 크기가 아닌 것에 유의할 것.
int decryptedLen = 0;
printf("sample_issacweb_symmetric_encryption() => ");
encryptedLen = issacweb_encrypt_ex(encrypted, (unsigned char *) plaintext, sizeof(plaintext), secretKey, ISSACWEB_SEED);
if (encryptedLen <= 0) {
printf("[ERROR] %s\n", errorcode_to_string(encryptedLen));
return 1;
}
decryptedLen = issacweb_decrypt_ex(decrypted, encrypted, encryptedLen, secretKey, ISSACWEB_SEED);
if (decryptedLen <= 0) {
printf("[ERROR] %s\n", errorcode_to_string(decryptedLen));
return 1;
}
printf("[OK]\n");
return 0;
}
int main() {
int result;
result = sample_setup();
if (result != 0) {
return result;
}
return sample_issacweb_symmetric_encryption();
}
EErrorCode
새롭게 구현된 내부 API 에서 사용되는 에러코드들
Definition: wasdk_errorcode.h:13
@ EEC_Success
성공
Definition: wasdk_errorcode.h:14
WA_SDK_API int FUNCCALL issacweb_decrypt_ex(void *outbuf, void *input, int input_len, void *key, int cipher_id)
암호문을 복호화한다.
WA_SDK_API int FUNCCALL issacweb_encrypt_ex(void *outbuf, void *input, int input_len, void *key, int cipher_id)
평문을 암호화한다.
@ ISSACWEB_SEED
SEED
Definition: issacweb.h:53
WA_SDK_API const char *FUNCCALL wasdk_error_message(EErrorCode errorCode)
에러코드에 해당하는 에러 메시지를 가져온다.
WA_SDK_API EErrorCode FUNCCALL wasdk_init(void)
모듈 초기화를 실행한다.
EXTERNC const char * errorcode_to_string(int code)