SOL9 Sample: RC

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * RC.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



// SOL9 2009/02/22

#include <sol/crypt/CryptServiceProvider.h>
#include <sol/crypt/SymmetricKey.h>


void _tmain(int argc, TCHAR** argv)
{

  try {
    //Default (PROV_RSA_AES) crypt service provider
    CryptServiceProvider csp;
    {
      printf("RC2\n");
    
      SymmetricKey aes(csp, CALG_RC2);
      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("RC4\n");
    
      SymmetricKey aes(csp, CALG_RC4);
      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("RC5\n");
    
      SymmetricKey aes(csp, CALG_RC5);
      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.decrypt(buffer, &dsize, TRUE);
      printf("2 SIZE=%d DATA=[%s]\n", dsize, (char*)buffer);    
    }

  } catch (Exception& ex) {
    printf("Exception = %s\n", ex.getErrorMessage());
  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.