Can anyone help me to reconvert im2uint16 back to image?

plaintextUnicodeVals = im2uint16(plaintext);
%display(plaintextUnicodeVals);
plaintextBytes = im2uint8(plaintextUnicodeVals);
display(plaintextBytes);
ciphertext = cipher.doFinal(plaintextBytes)' %'
display(ciphertext);
how to convert back to image after decrypting cipher?

Answers (1)

Arya - it seems that you are using the Java cryptography cipher class (see https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html) to encrypt your message. If we use RSA, which has a limit of 117 bytes for the plaintext message, then we could encrypt and decrypt as
import javax.crypto.Cipher;
% initialize the plaintext message
plaintext = 'I want to encrypt this message';
% initialize the cipher to encrypt
cipher = Cipher.getInstance('RSA');
keygen = java.security.KeyPairGenerator.getInstance('RSA');
keyPair = keygen.genKeyPair();
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPrivate());
% encrypt the message
ciphertext = cipher.doFinal(int8(plaintext));
% initialize the cipher to decrypt
cipher.init(Cipher.DECRYPT_MODE, keyPair.getPublic());
% decrypt the message
decryptedtext = char(uint8(cipher.doFinal(ciphertext)))'
Since you are encrypting an image, you may be using a different encryption algorithm (one that allows more than the 117 bytes for RSA).

4 Comments

Thank you Mr.Geoff Hayes, I didn't know about the 117 bytes limit for RSA, could you please let me know a better algorithm or library function to encrypt and decrypt MRI images. Thanks again.
Aria - I don't understand why you want to encrypt an MRI image. For what purpose?
Arya's answer moved here
Sir, I am sending the MRI image as a part of my project In order to provide security,I have to use some better algorithms for encryption before transmitting the image.
Arya - you may want to encrypt blocks of the images where a block is (say) 100 bytes. Then you could use the above code to encrypt the image.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 4 Feb 2016

Commented:

on 8 Feb 2016

Community Treasure Hunt

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

Start Hunting!