简体   繁体   English

如何在Codeigniter RSA库中生成签名和密钥

[英]How to generate signature and keys in Codeigniter RSA library

I am doing some encryption and decryption in php using codeigniter framework. 我正在使用codeigniter框架在php中进行一些加密和解密。 I am using this library https://github.com/Dirktheman/rsa-codeigniter-library . 我正在使用这个库https://github.com/Dirktheman/rsa-codeigniter-library What I want to do is I generate a signature like this encrypt_method(value,private_key) . 我想要做的是生成一个像encrypt_method(value,private_key)这样的签名。

That will return signature. 那将返回签名。 Then I want to verify the value that is equal to out previous value or not decrypt(signature,previous_input,public_key). 然后,我想验证等于先前值的值或不解密(签名,previous_input,public_key)。 What my problem is there is no method to generate private and public key. 我的问题是没有生成私钥和公钥的方法。 For generating signature as well. 用于生成签名。 So, how can I achieve it using RSA library in PHP? 那么,如何使用PHP中的RSA库实现它?

Do not use that library. 不要使用该库。 It is completely insecure. 这是完全不安全的。

A secure RSA implementation depends on the use of randomly generated large prime numbers (eg, at least 2048 bits!) as part of a private key. 安全的RSA实现取决于将随机生成的质数(例如,至少2048位!)用作私钥的一部分。 However, this library does not use large prime numbers, nor does it even generate them randomly — it picks them from an array of 570 pregenerated four-digit numbers . 但是,该库不使用大质数,甚至也不随机生成它们- 它从570个预生成的四位数字数组中选择它们 This means that there are only about 162,000 (570 * 569 ÷ 2) possible keys that could be generated; 这意味着只能生成大约162,000(570 * 569÷2)个可能的密钥。 this is few enough that you could easily generate a list of all possible public and private key pairs. 这足够少,您可以轻松生成所有可能的公共和私有密钥对的列表。

Additionally, this library is using RSA in an inappropriate mode. 此外,该库在不适当的模式下使用RSA。 It is "encrypting" and "decrypting" messages by encrypting each group of three letters as a separate, independent message. 它通过将每组三个字母作为单独的独立消息进行加密来“加密”和“解密”消息。 This scheme is insecure, as the individual blocks can be edited and reordered to create new messages. 这种方案是不安全的,因为可以对各个块进行编辑和重新排序以创建新消息。 (For instance, an encrypted message that said SEND JO $123 could easily be edited to say SEND JO $123123 by repeating the last block!) Worse, if the content of one message is known, it is possible to search for blocks from that first message within another message to recover parts of its contents. (例如,通过重复最后一个块,可以很容易地将一条加密消息“ SEND JO $123编辑为SEND JO $123123 !)更糟糕的是,如果知道一条消息的内容,则可以从该第一条消息中搜索块在另一封邮件中以恢复其部分内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM