- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 C++ 的 Crypto++
库,使用磁盘上的公钥和我的私钥来加密 128 位消息。但是,当我调用我的函数时,程序终止并显示错误消息:
terminate called after throwing an instance of 'CryptoPP::InvalidArgument' what(): RSA/OAEP-MGF1(SHA-1): message length of 256 exceeds the maximum of 214 for this public key
我不确定为什么它认为我的消息是 256 位的,而它们显然是 128 位的。下面是我的代码:
std::string encryptWithBothKeys(std::string key_name1, std::string key_name2, std::string plain){
std::string cipher1, cipher2;
AutoSeededRandomPool rng;
RSA::PublicKey pub_key;
RSA::PrivateKey priv_key;
loadPublicKey(key_name1, pub_key);
loadPrivateKey(key_name2, priv_key);
RSAES_OAEP_SHA_Encryptor e_pub(pub_key);
RSAES_OAEP_SHA_Encryptor e_priv(priv_key);
StringSource ss1(plain, true,
new PK_EncryptorFilter(rng, e_pub,
new StringSink(cipher1)
)
);
StringSource ss2(cipher1, true,
new PK_EncryptorFilter(rng, e_priv,
new StringSink(cipher2)
)
);
return cipher2;
}
void load(const std::string& filename, BufferedTransformation& bt){
FileSource file(filename.c_str(), true /*pumpAll*/);
file.TransferTo(bt);
bt.MessageEnd();
}
void loadPrivateKey(const std::string& filename, PrivateKey& key){
ByteQueue queue;
load(filename, queue);
key.Load(queue);
}
void loadPublicKey(const std::string& filename, PublicKey& key){
ByteQueue queue;
load(filename, queue);
key.Load(queue);
}
在主函数中我这样调用它:
std::string encrypted_msg = encryptWithBothKeys("their.pub", "my.key", "0123456789ABCDEF");
有什么建议吗?
编辑:第一次加密后的密文大小为 256。我想我需要弄清楚为什么它会增加大小。
最佳答案
I'm not sure why it thinks my messages are 256-bit when they are clearly 128-bit. Below is my code:
那些是字节,而不是位。
您使用的是什么大小的 RSA 模数?我猜它是一个 2048 位的 key ,即 256 字节,由于 OAEP 填充,剩下 ≈214 字节。
所以问题就变成了,在这期间plain
和cipher1
的大小是多少:
StringSource ss1(plain, true,
new PK_EncryptorFilter(rng, e_pub,
new StringSink(cipher1)
)
);
我的猜测是 plain1
足够小。然而,当它被填充和加密时,它扩展到 256 字节作为 cipher1
。所以执行时消息 cipher1
太大了:
StringSource ss2(cipher1, true,
new PK_EncryptorFilter(rng, e_priv,
new StringSink(cipher2)
)
);
此外,上面是否应该使用 PK_DecryptorFilter
?您确定要再次加密吗?如果是这样,那你为什么要使用 e_priv
?
使用私钥加密不是有效的加密操作。如果您想要“使用私钥加密”这件事,通常意味着您想要一个带恢复的概率签名方案 (PSSR)。 Crypto++ 提供了其中的几个。
关于c++ - 为什么 Crypto++ 认为我的消息比它们实际的要大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34035207/
我正在尝试更新一些较旧的代码以消除警告。我已经升级了一些使用加密模块的代码。然而,webpack 5.88.2没有识别新的语法。我的新导入内容如下所示:。完整的错误如下所示。这表明我可能需要另一个插件
是否有任何 C 或 C++ 函数可以产生与此 python 代码相同的输出(SHA512 with salt)? import crypt; crypt.crypt('test', '$6$Salte
我正在开发一个使用 Crypto++ 使用 RSA 加密一些数据的项目。 这是我的 Crypto++ 代码: string plain = "Text123", encoded, cipher; st
收到错误,因为 require 不是一个函数,尝试在 typescript 组件中使用加密 js 函数 // Load modules 'use strict'; var Crypto = requi
我正在尝试将下面的java代码转换为nodejs。 public static String encrypt(String accessToken) throws Exception {
我有一个旨在在 Node.js 中使用的签名方法,但我想使用 crypto-js 在客户端实现它。它应该可以在最新的 Chrome 版本中运行。 我尝试遵循以下一些答案:Decode a Base64
我想知道 Crypto.Signature.PKCS1_v1_5 和 Crypto.Signature.pkcs1_15 有什么区别? 在documentation他们使用此函数 Crypto.Sig
我们有一个使用 Crypto++ 库的 ECC 部分的 C++ 解决方案,但必须转移到 .NET 解决方案。由于 Microsoft 的 ECC 代码的文档最少,我目前正在试验文档最少的 Bouncy
我在验证 Web Crypto API 创建的签名时遇到问题。 这是我用来在浏览器中生成 RSA key 的代码: let keys; const generateKeys = async () =>
嗨,所以我有一个运行 Crypto 的服务器,它工作得很好。我使用 electrojs 作为客户端,并且加密应该内置到 Node 中。当我尝试使用该模块时,它返回“crypto.scryptSync
使用 Apple 的 Common Crypto 和 Crypto++ 使用相同的 key 加密相同的文件(二进制数据)时,我得到了不同的结果。我使用的算法是 AES。 这是使用 Common Cry
如何存储 crypto.createHash('sha1') 的当前状态(在它被 hash.update(buffer) 填充后)以在另一个地方使用它http请求可能发生在node.js的不同进程?
我正在使用 NodeJS 的捆绑 crypto服务器端的 SHA256 哈希模块。在客户端,我使用一个名为 Crypto-JS 的 javascript 库. 我将 SHA256 哈希值用于使用基于经
我想编写一个使用 linux crypto-api 进行数字签名的 C 程序。不幸的是,我找不到关于 linux api 和 linux/crypto.h 中定义的函数的良好文档(谷歌搜索没有帮助,这
我正在尝试使用 JUNIT 在实际执行 AES 加密的方法中模拟 cipher.doFinal()。我在启动 JUNIT 测试用例时遇到异常 "Tried to access class javax.
您好,我在Liferay dxp项目中使用Paytm校验和依赖项 但我得到error :com.sun.crypto.provider.AESCipher$General cannot be cast
我正在尝试使用 crypto-js javascript 库加密数据,并尝试使用 Node 加密库在 Nodejs 端解密相同的加密文本。我正在使用 AES 256 加密算法和 CTR 模式,没有填充
我想了解 javax.crypto.Mac 之间的区别和 javax.crypto.Cipher 。这两个类看起来非常相似(它们具有相似的方法,但是这两个类并不互相继承)。 这两个类之间的根本区别是什
我正在尝试在设备上生成 SHA256 和 HmacSHA512 哈希值,不幸的是,该设备不支持标准 Node crypto 库。所以我正在调整代码以使用 CryptoJS 代替。但是,CryptoJS
我正在使用 Android FingerPrintManager API 并使用 KeyPairGenerator 创建 key 对,我想使用公钥加密密码,然后在用户通过输入 fingerPrint
我是一名优秀的程序员,十分优秀!