【源码】基于最优非对称加密填充的RSA加密
使用最优非对称加密填充的RSA加密,使用matlab对查询文件中的文本进行加密和解密。
RSA encryption using Optimal Asymmetric Encryption Padding with matlab which encrypts and dycrypts text in a query file.
该代码还需要vpi工具包:
you will need only the vpi package: https://www.mathworks.com/matlabcentral/fileexchange/22725-variable-precision-integer-arithmetic
简介
Introduction
RSA是一种著名的加解密系统,经常与OAEP一起使用,以保证数据的安全性。
RSA is a famous encryption-decryption system which is oftenly used along with the OAEP to ensure the security of the data.
使用随机n位素数,在OAEP将字符uint8表示转换为随机编码之后,rsa加密一个消息,采用的是随机oracle hash函数,如SHA-256。
Using random n bits primes the rsa is encrypting a messege after the OAEP converts the charachters uint8 representation to random encoding using random-oracle hash functions like SHA-256 which is used here.
RSA使用这两个随机素数生成公钥和私钥,用公钥加密消息并将其保存在一个文件中,然后使用私钥在另一个文件中解密,从而在发送方获得OAEP生成的数字。
the RSA then uses the two random primes to generate the public and the private keys, encrypt the messege with the public key save it in a file and then decrypt it in another file using the private key to get the numbers generated by the OAEP earlier on the sender side.
OAEP解密消息并取回原始消息并将其保存在一个文件夹中。
The OAEP decrypts the messege and gets the original messege back and saves it in a folder.
局限性
Limitations
由于vpi包在计算中花费了大量时间,所以代码运行速度很慢。
* The code is slow as the vpi package takes a big time in calculations.
为提高运行速度可以考虑以下的方法:
You can try using one of the alternatives in this post to boost speed: https://www.mathworks.com/matlabcentral/answers/116949-big-integer-speed-vpi-and-symbolic
函数isprime可以进一步提高运算速度,或者使用不同于fermat定理的先验检查。
* The function isprime can be further improved to make the time costly check more fast or to use prior check different than fermat's little theorem that is more percise.
This link can be helpful: https://www.geeksforgeeks.org/prime-numbers/ (I suggest using Lucas test)