All pastes #14046 Raw Edit

Anonymous

public text v1 · immutable
#14046 ·published 2005-06-12 12:40 UTC
rendered paste body
#include <string.h>
#include <stdio.h>

// #include <matrixSsl.h>

#include "/import/src/matrixssl/src/matrixConfig.h"
#include "/import/src/matrixssl/src/matrixInternal.h"

static char keyfile[] = "key.pem";
static char certfile[] = "cert.pem";
static char CAfile[] = "CA.pem";


int main( int argc, char** argv ) {
   if ( argc < 1 ) {
           fprintf(stderr, "Usage unras infile outfile");
        return 1;
   }

   int32 x;
   sslKeys_t  *keys;

   psPool_t *pool;
   sslRsaKey_t *key;
   unsigned char *in;
   int32 inlen;
   unsigned char *out;
   int32 outlen;

   /*Initialize the MatrixSSL Library, and read in the certificate file
   used to validate the server.
   */
   if (matrixSslOpen() < 0) {
        fprintf(stderr, "matrixSslOpen failed, exiting...\n");
        return -1;
   }
   if (matrixRsaReadPrivKey(keyfile, NULL, &key) < 0) {
        fprintf(stderr, "matrixSslReadkeys failed, exiting...\n");
        return -1;
   }
   /*if (matrixSslReadKeys(&keys, NULL , keyfile, NULL, NULL) < 0) {
        fprintf(stderr, "matrixSslReadkeys failed, exiting...");
        return -1;
   }
   */


   FILE* f;
   int i, rawLen, compLen;
   unsigned char* rawBlock;
   unsigned char* compBlock;

   f = fopen( argv[ 1 ], "rb" );
   if ( !f )
         abort();
   fseek( f, 0, SEEK_END );
   rawLen = ftell( f );
   fseek( f, 0, SEEK_SET );
   in= (unsigned char*)malloc( rawLen );
   out= (unsigned char*)malloc( rawLen );
   fread( in, 1, rawLen, f );
   fclose( f );

   printf("Keylen: %d\n",key->size);
   printf("rawLen: %d\n",rawLen);

   if (matrixRsaDecryptPriv(NULL,key, in, rawLen,out, 108) < 0) {
        fprintf(stderr, "matrixRsaDecryptPriv failed, exiting...\n");
        return -1;
   }

   f = fopen( argv[ 2 ], "wb" );
   if ( !f )
          abort();

   fwrite( out, rawLen,1 , f );
   fclose( f );

}