Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return and display the RSA ciphertext when encrypted in Java
    text
    copied!<p>I am writing a simple java programs to encrypt/decrypt using DES and RSA algorithms using Java. In Java, in order to encrypt and decrypt using the function <code>doFinal</code>, I have to conver the message (plain text) into bytes. I used the function <code>.getBytes</code> to do so. Here is part of the code:</p> <pre><code>Cipher desCipher // Create the cipher desCipher = Cipher.getInstance("DES/ECB/NoPadding"); desCipher.init(Cipher.ENCRYPT_MODE, myDesKey); byte[] textEncrypted = desCipher.doFinal(msgBytes); </code></pre> <p>Then, return it as:</p> <pre><code>return new String(base64Cipher); </code></pre> <p>In this case, I get the cipher text looks in strange characters suc as:</p> <pre><code>Encrypted Message: °;zRfwجvë ‏“ëثw‰ڑل7دM#¼7وm‡î¤ </code></pre> <p>In some internet tutorials, they used Base64 encoding before returning the cipher such as this reference: <a href="http://techie-experience.blogspot.com/2012/10/encryption-and-decryption-using-aes.html" rel="nofollow">http://techie-experience.blogspot.com/2012/10/encryption-and-decryption-using-aes.html</a></p> <p>When I used Base64 as follows:</p> <p>byte[] textEncrypted = desCipher.doFinal(msgBytes);</p> <pre><code>// converts to base64 for easier display. byte[] base64Cipher = Base64.encodeBase64(textEncrypted); return new String(base64Cipher); </code></pre> <p>The cipher text appears in alpha and numerical characters as:</p> <pre><code>Encrypted Message: Xz93ODw3gEKm3hziPr0UJ+ed55nWLGpTR9uHjZjLwtg= </code></pre> <p>Which method is correct? Does RSA cipher supposed to be in alpha-numeric characters only? If not, why that referee suggests using it ? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload