Version 1.1.0 (8.07 KB) by Ahmed Salah
RSA-OAEP encryption-decryption using matlap
Updated 24 Aug 2020


RSA encryption using Optimal Asymmetric Encryption Padding with matlab which encrypts and dycrypts text in a query file.


you will need only the vpi package:


RSA is a famous encryption-decryption system which is oftenly used along with the OAEP to ensure the security of the data.

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.

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.

The OAEp decrypts the messege and gets the original messege back and saves it in a folder.


* 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:

* 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: (I suggest using Lucas test)

Cite As

Ahmed Salah (2024). RSA-OAEP-matlab (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

See release notes for this release on GitHub:


To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.