Giter VIP home page Giter VIP logo

aes-rsa-cpp-java's Introduction

Summary

This is a demo about "Match C++ and Java AES,RSA Encryption and Decryption Results"

C++ Encryption and Decryption

Use Crypto++ (http://www.cryptopp.com/)

I ignore the "cryptopp561.a", because it's too big (130M)

The more information is in CryptoPP-for-iOS

Also you can compile Crypto++ with yourself

AES

Use the "AES/CBC/PKCS5Padding"

AES Java Demo

// key
byte[] key = "0123456789abcdef".getBytes("UTF-8");
// iv
byte[] iv = "fedcba9876543210".getBytes("UTF-8");

byte[] indata = "bsmith is a good guy.".getBytes("UTF-8");
//dump("indata", indata);

AES aes = new AES();
aes.init(key, iv);

// encrypt.
byte[] outdata = aes.encrypt(indata);
//dump("outdata", outdata);

// decrypt.
byte[] indata1 = aes.decrypt(outdata);
//dump("indata1", indata1);

AES C++ Demo

// key
const char * key = "0123456789abcdef";
// iv
const char * iv = "fedcba9876543210";

AES aes;
aes.init(key, 16, iv);

{
	// decrypt.
	int maxinlen = aes.getPlainLen(encryptSize);
	char * orgdata = new char[maxinlen];
	{
		int orglen = aes.decrypt(encryptBuffer, encryptSize, orgdata);
		//printf("decryptWithCrypto++(hex)=");
		//dump(orgdata, orglen);
	}
	delete [] orgdata;
}

{
	// encrypt.
	int maxoutlen = aes.getCipherLen(decryptSize);
	char * outdata = new char[maxoutlen];
	int outlen = 0;
	{
		outlen = aes.encrypt(decryptBuffer, decryptSize, outdata);
		//printf("encryptWithCrypto++(hex)=");
		//dump(outdata, outlen);
	}
	delete [] outdata;
}

RSA

Use the "RSA PKCS #1"

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.