hi,I came up the same problem,do you fix it out?
在 2015年5月12日星期二 UTC+8下午3:08:12,Brian写道:
>
> // c# code
> private byte[] _iv;
> private readonly string key = "7794b12op901252bfcea66d6f0521212";
> public string decrypt(string Input)
> {
> string str = "";
> RijndaelManaged managed = new RijndaelManaged();
> managed.KeySize = 128;
> managed.BlockSize = 128;
> managed.Mode = CipherMode.CBC;
> managed.Padding = PaddingMode.Zeros;
> managed.Key = Encoding.UTF8.GetBytes(this.key);
> managed.IV = this._iv;
> try
> {
> ICryptoTransform transform = managed.CreateDecryptor();
> byte[] bytes = null;
> using (MemoryStream stream = new MemoryStream())
> {
> using (CryptoStream stream2 = new CryptoStream(stream,
> transform, CryptoStreamMode.Write))
> {
> byte[] buffer = Convert.FromBase64String(Input);
> stream2.Write(buffer, 0, buffer.Length);
> }
> bytes = stream.ToArray();
> }
> str = Encoding.ASCII.GetString(bytes);
> }
> catch (Exception)
> {
> }
> return str;
> }
> public string encrypt(string Input)
> {
> RijndaelManaged managed = new RijndaelManaged();
> managed.KeySize = 128;
> managed.BlockSize = 128;
> managed.Mode = CipherMode.CBC;
> managed.Padding = PaddingMode.Zeros;
> managed.Key = Encoding.ASCII.GetBytes(this.key);
> managed.GenerateIV();
> this._iv = managed.IV;
> ICryptoTransform transform = managed.CreateEncryptor(managed.Key,
> managed.IV);
> byte[] inArray = null;
> using (MemoryStream stream = new MemoryStream())
> {
> using (CryptoStream stream2 = new CryptoStream(stream, transform,
> CryptoStreamMode.Write))
> {
> byte[] bytes = Encoding.UTF8.GetBytes(Input);
> stream2.Write(bytes, 0, bytes.Length);
> }
> inArray = stream.ToArray();
> }
> return Convert.ToBase64String(inArray);
> }
>
> QT code
> QString aeskey = "7794b12op901252bfcea66d6f0521212";
> QString _iv;
> void Cipher::GenerateIV()
> {
> AutoSeededRandomPool rnd;
> byte iv3[AES::BLOCKSIZE];
> rnd.GenerateBlock(iv3, AES::BLOCKSIZE);
> QByteArray out((char*)iv3, AES::BLOCKSIZE);
> _iv = out.toBase64();
> }
> QString Cipher::AESencrypt(QString Qstr_in)
> {
> string str_in = Qstr_in.toStdString();
> string key = aeskey.toStdString();
> GenerateIV();
> string iv = _iv.toStdString();
> string str_out;
> CBC_Mode<AES>::Encryption encryption;
> encryption.SetKeyWithIV((byte*)key.c_str(), key.length(),
> (byte*)iv.c_str());
> StringSource encryptor(str_in, true,
> new StreamTransformationFilter(encryption,
> new Base64Encoder(
> new StringSink(str_out)
> // ,StreamTransformationFilter::PKCS_PADDING
> ,StreamTransformationFilter::ZEROS_PADDING
> )
> )
> );
>
> return QString::fromStdString(str_out);
> }
> QString Cipher::AESdecrypt(QString Qstr_in)
> {
> string str_in = Qstr_in.toStdString();
> string key = aeskey.toStdString();
> string iv = _iv.toStdString();
> string str_out;
> CBC_Mode<AES>::Decryption decryption;
> decryption.SetKeyWithIV((byte*)key.c_str(), key.length(),
> (byte*)iv.c_str());
> StringSource decryptor(str_in, true,
> new Base64Decoder(
> new StreamTransformationFilter(decryption,
> new StringSink(str_out)
> // ,StreamTransformationFilter::PKCS_PADDING
> ,StreamTransformationFilter::ZEROS_PADDING
> )
> )
> );
> return QString::fromStdString(str_out);
> }
>
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.