Can anyone help me to reconvert im2uint16 back to image?
Show older comments
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)
Geoff Hayes
on 5 Feb 2016
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
Arya Sebastian
on 5 Feb 2016
Geoff Hayes
on 5 Feb 2016
Aria - I don't understand why you want to encrypt an MRI image. For what purpose?
Geoff Hayes
on 8 Feb 2016
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.
Geoff Hayes
on 8 Feb 2016
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.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!