1 Screenshot
2 Source code
/*
* DES.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9 2009/02/22
// 2009/02/23 Added an example of CALG_3DES_112 (TWO KEY)
/*
CALG_DES DES
CALG_DESX DESX
CALG_3DES Triple DES
CALG_3DES_112 112bits 2KeyDES
*/
#include <sol/crypt/CryptServiceProvider.h>
#include <sol/crypt/SymmetricKey.h>
int _tmain(int argc, TCHAR** argv)
{
int rc = 0;
try {
//Default (PROV_RSA_AES) crypt service provider
CryptServiceProvider csp;
{
printf("DES\n");
SymmetricKey aes(csp, CALG_DES);
const size_t size = 128;
size_t dsize = size;
const size_t bsize = size+ 128;
unsigned char buffer[bsize];
memset(buffer, 0, sizeof(buffer));
strcpy_s((char*)buffer, SizeOf(buffer), "This is a sample text.Hello world!");
printf("1 SIZE=%d DATA=[%s]\n", dsize, (char*)buffer);
aes.encrypt(buffer, &dsize, bsize, TRUE);
aes.decrypt(buffer, &dsize, TRUE);
printf("2 SIZE=%d DATA=[%s]\n", dsize, (char*)buffer);
}
{
printf("\n");
printf("3DES_2KEY\n");
SymmetricKey aes(csp, CALG_3DES_112);
const size_t size = 128;
size_t dsize = size;
const size_t bsize = size+ 128;
unsigned char buffer[bsize];
memset(buffer, 0, sizeof(buffer));
strcpy_s((char*)buffer, SizeOf(buffer), "This is a sample text.Hello world!");
printf("1 SIZE=%d DATA=[%s]\n", dsize, (char*)buffer);
aes.encrypt(buffer, &dsize, bsize, TRUE);
aes.decrypt(buffer, &dsize, TRUE);
printf("2 SIZE=%d DATA=[%s]\n", dsize, (char*)buffer);
}
{
printf("\n");
printf("3DES\n");
SymmetricKey aes(csp, CALG_3DES);
const size_t size = 128;
size_t dsize = size;
const size_t bsize = size+ 128;
unsigned char buffer[bsize];
memset(buffer, 0, sizeof(buffer));
strcpy_s((char*)buffer, SizeOf(buffer), "This is a sample text.Hello world!");
printf("1 SIZE=%d DATA=[%s]\n", dsize, (char*)buffer);
aes.encrypt(buffer, &dsize, bsize, TRUE);
aes.decrypt(buffer, &dsize, TRUE);
printf("2 SIZE=%d DATA=[%s]\n", dsize, (char*)buffer);
}
} catch (Exception& ex) {
printf("Exception = %s\n", ex.getErrorMessage());
}
rc = GetLastError();
return rc;
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.