Code Monkey home page Code Monkey logo

mgcryptor's People

Contributors

megabri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mgcryptor's Issues

Encode and Decode in two steps example

Hi

I am struggling to create an example with this. I am trying to create a simple C program with this library to which I can pass 3 arguments:

  1. string to encode / decode
  2. passphrase
  3. encode or decode

I want the program to either encode or decode what I input so it can be used to first encode something and at a later time to decode it.

So for a very simple example I type:
"main test 1234 e" -> so encode (e) "test" with passphrase "1234", that yields:

MGCryptor total encrypted data frame:
020167C6697351FF4AEC765A2E63339FC99A29CDBAABF2FBE3467CC254F81BE8E78DAB3833E19072EDCEFBEE6C90D65A38E338E30FCA10AC918562A95784A03DD2B4B72879F5

Now I want to be able to use:
"main 020167C6697351FF4AEC765A2E63339FC99A29CDBAABF2FBE3467CC254F81BE8E78DAB3833E19072EDCEFBEE6C90D65A38E338E30FCA10AC918562A95784A03DD2B4B72879F5 1234 d" -> so decode (d) "0201...." with passphrase "1234"
this does not return my original string input.

I have tried converting it to a buffer via "http://stackoverflow.com/questions/18267803/how-to-correctly-convert-a-hex-string-to-byte-array-in-c" but that does not work.

What am I missing?

Currently my code is

//
//  main.c
//
//  Copyright (c) 2013 Gabriele Merlonghi
//
//  This code is licensed under the MIT License:
//
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//

/* This is the demo file for MGCryptor library
 *
 * In this demo there is a pre-defined message text to encrypt and the password
 * used for encrypt and decrypt.
 *
 * The encrypted data output is composed by the AES 128 bit with random IV
 * (Initialization Vector). The 128 bit keys is derived from password with
 * PBKDF2 algorithm, with random 8 bytes salt and 10000 iterations.
 * Finally all data output is hashed by HMAC-SHA1 algorithm with another 16 bit
 * key derived always with PBKDF2 and another random salt.
 *
 * The decryption follow the inverse process.
 *
 *
 */


#include "MGCryptor.h"
#include "MGEncryptor.h"
#include "debuglog.h"   //for debug purpose only

int main(int argc, char *argv[]) {

    if( argc == 4 ) {
        //printf("The argument supplied is %s\n", argv[1]);

        char *message = strdup(argv[1]);
        char *password = strdup(argv[2]);

        if (strcmp(argv[3], "e") == 0){
            printf("encoding... \n");

            puts("***** Start Encrypt Procedure *****"); //48656C6C6F

            /* define here the data for output encryption */
            int cipherBufferLen;
            static unsigned char cipherBuffer[CIPHER_BUFFER_LEN];

            cipherBufferLen = MGEncryptor(message, sizeof(message), password, sizeof(password), cipherBuffer);

            puts("Input Text in Hex");
            printHexBuffer(message, sizeof(message));
            puts("\n");

            puts("MGCryptor password:");
            printHexBuffer(password, sizeof(password));
            puts("\n");

            puts("MGCryptor total encrypted data frame:");
            printHexBuffer((char *)cipherBuffer, cipherBufferLen);

            printf("\n cipherBuffer: %d \n", (char *)cipherBuffer);
            printf("\n cipherBufferLen: %d \n", cipherBufferLen);

            puts("\n");

            puts("***** End Encrypt Procedure *****");

        } else {
            printf("decoding... \n");

            puts("***** Start Decrypt Procedure *****");

            // define here the data for output decryption
            int plainBufferLen;
            static unsigned char plainBuffer[PLAIN_BUFFER_LEN];


            int cipherBufferLen = strlen(argv[1]);
            printf("\n cipherBufferLen: %d \n", cipherBufferLen);
            static unsigned char cipherBuffer[CIPHER_BUFFER_LEN];

            strcpy (cipherBuffer, argv[1]);


            printf("\n cipherBuffer: %s \n", cipherBuffer);

            plainBufferLen = MGDecryptor(cipherBuffer, cipherBufferLen, password, sizeof(password), plainBuffer);

            puts("MGCryptor total decrypted data frame:");
            printHexBuffer((char *)plainBuffer, plainBufferLen);
            puts("\n");

            puts("***** End Decrypt Procedure *****");
        }

        return 0;

    }
    else if( argc > 4 ) {
        printf("Too many arguments supplied.\n");
    }
    else {
        printf("One argument expected.\n");
    }   
}


Consider choosing a license

Hi,

just found your software and looks very promising. But I can't find a license.
Please consider adding a license (preferably an open source friendly one).
Also check if the code written / algorithms are somehow protected by someone else...

BR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.