shanet / crypto-example Goto Github PK
View Code? Open in Web Editor NEWA short, proof-of-concept RSA and AES encryption program with OpenSSL
License: MIT License
A short, proof-of-concept RSA and AES encryption program with OpenSSL
License: MIT License
when I open "#define CONVERT_TO_BASE64" can not decryptFile "Decryption failed"
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.
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;
}
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.】
}
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.