我应该把文字分成几块吗?
RSA是错误的加密方案吗?
我需要一个字符串加密的例子(在C++中 - >我在linux-Ubuntu上工作)和aes-cbc256以及填充:PKCS7请帮忙.
对于以下代码,如何将IV设置为0并将键值设置为字符串值?我还想添加pkcs7填充.我正在使用crypto ++ lib(在Linux中)
// Driver.cpp
//
#include "stdafx.h"
#include "cryptopp/dll.h"
#include "cryptopp/default.h"
#include "crypto++/osrng.h"
using CryptoPP::AutoSeededRandomPool;
#include <iostream>
using std::cout;
using std::cerr;
#include <string>
using std::string;
#include "crypto++/cryptlib.h"
using CryptoPP::Exception;
#include "crypto++/hex.h"
using CryptoPP::HexEncoder;
using CryptoPP::HexDecoder;
#include "crypto++/filters.h"
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::StreamTransformationFilter;
#include "crypto++/aes.h"
using CryptoPP::AES;
#include "crypto++/ccm.h"
using CryptoPP::CBC_Mode;
#include "assert.h"
int main(int argc, char* argv[])
{
AutoSeededRandomPool prng;
byte key[ AES::DEFAULT_KEYLENGTH ];
prng.GenerateBlock( key, sizeof(key) );
byte iv[ AES::BLOCKSIZE];
iv[AES::BLOCKSIZE] = 0;
//prng.GenerateBlock(iv, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Crypto ++(带有Code :: Blocks)创建一个C ++程序,但始终遇到相同的问题。我正在使用此代码的简化版本:http : //andreyvitdev.blogspot.com/2005/10/crypto-usage-sample.html ,但我无法对其进行编译。
#include "cryptopp/blowfish.h"
#include "cryptopp/osrng.h"
using namespace CryptoPP;
int main (int argc, char** argv) {
byte key[Blowfish::DEFAULT_KEYLENGTH],
iv[Blowfish::BLOCKSIZE];
AutoSeededRandomPool rng (true);
rng.GenerateBlock(key, sizeof (key));
rng.GenerateBlock(iv, sizeof (iv));
}
Run Code Online (Sandbox Code Playgroud)
我收到多个错误,开始于:“ C:\ Users \ Utilisateur \ Programming \ C ++ \ CodeBlocks \ Crytp tester \ main.cpp | 13 |未定义对`CryptoPP :: RandomNumberGenerator :: GenerateBlock的引用(未签名char *,未签名int) '”
我想念什么吗?在不同站点上有许多必须导入的库的引用,但是我不知道它们在crypto ++文件夹中的位置:http : //www.cryptopp.com/#download
我有一个C++应用程序,它使用Crypto ++将加密数据发送到PHP站点.但是,当数据进入PHP端时,它不会正确解密数据.
C++/Crypto ++代码:
char stupidKey[AES::MAX_KEYLENGTH] = "thisisastupidkeythisisastupidke";
ECB_Mode<AES>::Encryption aes((byte *)stupidKey, AES::MAX_KEYLENGTH);
std::string cypher;
StringSource(aData, true, new StreamTransformationFilter(aes, new StringSink( cypher )));
StringSource(cypher, true, new Base64Encoder( new StringSink(aOutput) ));
Run Code Online (Sandbox Code Playgroud)
PHP代码:
define('CRYPT_SECRET', 'thisisastupidkeythisisastupidke');
$postData = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,
CRYPT_SECRET, base64_decode($_POST['request']),
MCRYPT_MODE_ECB);
Run Code Online (Sandbox Code Playgroud)
注意:我知道ECB是加密模式的一个不好的选择,但是我希望能够在没有IV的额外奇怪之处的情况下使用它,然后使事情复杂化.
我遇到的问题类似于这里提出的问题.我有我认为是DER编码的RSA PKCS#1公钥,我想用它来验证我的其他数据/签名,但我甚至无法使解码工作.
我使用的是与该问题的解决方案中提出的相同的代码.
ByteQueue queue;
StringSource ss(key, true, new HexDecoder(new Redirector(queue)));
RSASSA_PKCS1v15_SHA_Verifier verifier;
verifier.AccessKey().BERDecodePublicKey(queue, false, 0);
AutoSeededRandomPool prng;
if (!verifier.AccessKey().Validate(prng, 3))
throw Exception(Exception::OTHER_ERROR, "Failed to validate public key");
Run Code Online (Sandbox Code Playgroud)
当我使用在该问题中发布的密钥时,代码可以正常运行,但是当我尝试使用它时,它会失败.我的格式错了吗?别的什么?我对加密很新,所以它可能是愚蠢/明显的东西......
这是我正在尝试使用的密钥.
30819D300D06092A864886F70D010101050003818B0030818702818100B126088
1BDFE84463D88C6AB8DB914A2E593893C10508B8A5ABDF692E9A5419A3EDBAE86
A052849983B75E3B425C18178B260003D857DF0B6505C6CF9C84F5859FCE3B63F
1FB2D4818501F6C5FA4AD1430EEB081A74ABD74CD1F4AA1FCCA3B88DD0548AED3
4443CEB52444EAE9099AA4FE66B2E6224D02381C248025C7044079020111
Run Code Online (Sandbox Code Playgroud)
编辑:
忘了提,这是我得到的错误:
Error!
Dynamic exception type: class CryptoPP::BERDecodeErr
std::exception::what: BER decode error
Run Code Online (Sandbox Code Playgroud) 我想知道是否有办法使用OpenSSL或Crypto ++库生成Cryptographic Nonce.还有什么比使用autoseeded池生成一组随机字节更多的东西吗?
我的iOS应用程序使用crypto ++作为静密库来保密.由于这个库是开源的,因此对于任何可能的错误行为者来说都是可见的,因此常识意味着应该没有麻烦.但是,根据美国出口管理条例第2部分第5类,我的应用程序似乎并没有明确豁免,但我无法确定,因为法律往往是一个令人费解的混乱的例外和随机的分裂,所以我希望向您提供在您的应用程序中包含开源加密库的实际经验(Android建议也可以):
我是否需要经历获得EAR批准的所有麻烦?
我在Windows中编译cryptopp项目时遇到以下错误。
C:\Users\Sajith\AppData\Local\Temp\ccxq8O8x.o:aescbc.cpp:(.text$_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[
__ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv]+0x2e): undefined reference to `CryptoPP::AlignedAllocate(unsig
ned int)'
C:\Users\Sajith\AppData\Local\Temp\ccxq8O8x.o:aescbc.cpp:(.text$_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPv
j[__ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj]+0x28): undefined reference to `CryptoPP::AlignedDeallocate
(void*)'
collect2.exe: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
下面是我的编译命令:
mingw32-g++.exe -o .\aestest2.exe .\aescbc.cpp -I "C:\cryptopp\Include" -L "C:\cryptopp\Lib" -lcryptopp
Run Code Online (Sandbox Code Playgroud)
我的libcryptopp.a位于C:\cryptopp\Lib
我试图找出AlignedDeallocate声明在哪里的地方,但我找不到。
引发此错误的程序部分如下:
try
{
cout << "plain text: " << plain << endl;
CBC_Mode< AES >::Encryption e;
e.SetKeyWithIV(key, sizeof(key), iv);
// The StreamTransformationFilter removes
// padding as required.
StringSource s(plain, true,
new StreamTransformationFilter(e,
new StringSink(cipher)
) // StreamTransformationFilter
); // StringSource
#if 0 …Run Code Online (Sandbox Code Playgroud) 以下是在C上使用cbc和pkcs7填充(和密码)加密的aes256的代码(Windows和C++(使用libcrypto ++的Ubuntu).加密结果不一样.为什么?
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
public static class AESEncryption
{
public static string Encrypt(byte[] PlainTextBytes, byte[] KeyBytes, string InitialVector)
{
try
{
byte[] InitialVectorBytes = Encoding.UTF8.GetBytes(InitialVector);
RijndaelManaged SymmetricKey = new RijndaelManaged();
SymmetricKey.Mode = CipherMode.CBC;
// SymmetricKey.Padding = PaddingMode.PKCS7;
ICryptoTransform Encryptor = SymmetricKey.CreateEncryptor(KeyBytes, InitialVectorBytes);
MemoryStream MemStream = new MemoryStream();
CryptoStream CryptoStream = new CryptoStream(MemStream, Encryptor, CryptoStreamMode.Write);
CryptoStream.Write(PlainTextBytes, 0, PlainTextBytes.Length);
CryptoStream.FlushFinalBlock();
byte[] CipherTextBytes = MemStream.ToArray();
MemStream.Close();
CryptoStream.Close();
//return ByteToHexConversion(CipherTextBytes);
return Convert.ToBase64String(CipherTextBytes);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试加密一个简单的字符串,例如"Hello World!" 通过Crypto ++,通过Crypto ++解密成功.但是通过OpenSSL命令解密Crypto ++加密结果时出错了.
我的C++代码:
#include <iostream>
#include <aes.h>
#include <base64.h>
#include <modes.h>
std::string aes_encrypt(std::string key, std::string plain)
{
std::string result;
CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption ecb_encryptor((byte *)key.c_str(), CryptoPP::AES::MAX_KEYLENGTH);
auto encryptor = new CryptoPP::StreamTransformationFilter(ecb_encryptor,
new CryptoPP::Base64Encoder(new CryptoPP::StringSink(result), false),
CryptoPP::StreamTransformationFilter::ZEROS_PADDING);
CryptoPP::StringSource(plain, true, encryptor);
return result;
}
std::string aes_decrypt(std::string key, std::string cipher)
{
std::string result;
CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption ecb_decryptor((byte *)key.c_str(), CryptoPP::AES::MAX_KEYLENGTH);
auto decryptor = new CryptoPP::Base64Decoder(new CryptoPP::StreamTransformationFilter(ecb_decryptor,
new CryptoPP::StringSink(result),
CryptoPP::StreamTransformationFilter::ZEROS_PADDING));
CryptoPP::StringSource(cipher, true, decryptor);
return result;
}
int main(int argc, char **argv)
{
const char *key = …Run Code Online (Sandbox Code Playgroud)