Giter Club home page Giter Club logo

crypto-example's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crypto-example's Issues

Compile error

Error given:

base64.cpp:39:44: error: invalid conversion from ‘const void*’ to ‘void*’ [-fpermissive]
   BIO *bio = BIO_new_mem_buf(b64message, -1)
g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.

I fixed it on my copy but have never sent in a bug fix before so I am not sure how to.

【BUG】The base64 generated string contains garbled characters。

My code:

	string aes_encode(string _data, string _key, string _iv) {
		Crypto crypto;
		unsigned char *_aes_decode = NULL;
		// key
		int _key_code = crypto.setAesKey((unsigned char*)_key.c_str(), _key.size());
		if (_key_code == -1) return to_string(_key_code);
		// iv
		int _iv_code = crypto.setAesIv((unsigned char*)_iv.c_str(), _iv.size());
		if (_iv_code == -1) return to_string(_iv_code);
		// aes
		int _aes_encode_size = crypto.aesEncrypt((const unsigned char*)_data.c_str(), _data.size() + 1, &_aes_decode);
		if (_aes_encode_size == -1) return "";
		// base64 【The string generated here has a certain chance of being garbled.】
		char *_base64_encode = base64Encode(_aes_decode, _aes_encode_size);
		// result
		string _str_data = _base64_encode;
		free(_aes_decode);
		_aes_decode = NULL;
		return _str_data;
	}

I call this loop:
_20180507202148

result:
_20180507201737

Please help me, I checked for a long time to find this reason.

I also encountered the same problem in aes_decode, but I solved it this way.

	string aes_decode(string _base64_encode, string _key, string _iv) {
		Crypto crypto;
		unsigned char *_aes_encode = NULL;
		unsigned char *_aes_decode = NULL;
		// key
		int _key_code = crypto.setAesKey((unsigned char*)_key.c_str(), _key.size());
		if (_key_code == -1) return to_string(_key_code);
		// iv
		int _iv_code = crypto.setAesIv((unsigned char*)_iv.c_str(), _iv.size());
		if (_iv_code == -1) return to_string(_iv_code);
		// base64
		int _aes_encode_size = base64Decode(_base64_encode.c_str(), _base64_encode.size(), (unsigned char**)&_aes_encode);
		if (_aes_encode_size == -1) return "";
		// aes
		int _aes_decode_size = crypto.aesDecrypt((unsigned char*)_aes_encode, _aes_encode_size, (unsigned char**)&_aes_decode);
		if (_aes_decode_size == -1) return "";
		// result
		string _str_data = (char*)_aes_decode;
		free(_aes_encode);
		free(_aes_decode);
		_aes_decode = NULL;
		_aes_encode = NULL;
		return _str_data.substr(0, _aes_decode_size); // 【It must be intercepted in order to avoid garbled.】
	}

RSA encryption problem

so as u know the AES key generates at a size of 64, i would like to encrypt that key with client's RSA public key, so I did, but the encrypted msg length is always 80, doesn't matter what the RSA key length is (1024, 2048, 4096 etc) the encrypted msg in that situation should be always bits/8.
im using 1024 bits so my encrypted aes key should be about the size of 128, if its not a problem so pls help me understand, i tried the same system in python and in python it works as it should.

Encrypt/dencrypt with key?

Please add encrypting and dencrypt with key.
example:

Message to AES encrypt: encrypted sring
Key for encrypt: md5/sha1/another key type
Encrypted message: E+ERlsT/PQqItz71GcdFjU/nbWjELuKs4BbSVpqXLsk=
Key for decrypt: md5/sha1/another key type
Decrypted message: encrypted sring

Message to RSA encrypt: encrypted sring
Key for encrypt: md5/sha1/another key type
Encrypted message: i9ex4bu07siHvZZKCUzuQCH7AEdRKRhOjq6z+9HhWuY=
Key for decrypt: md5/sha1/another key type
Decrypted message: encrypted sring

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.