Note that there are some explanatory texts on larger screens.

plurals
  1. POEncrypt a string in Java so that a C program can decrypt it, without any padding in the decrypted text?
    primarykey
    data
    text
    <p>I am doing a simple AES encryption in Java:</p> <pre><code>Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, getAES128SecretKey()); byte[] encrypted = cipher.doFinal(input); </code></pre> <p>The output is converted to hex and stored in a database.</p> <p>A later process (one written in C/C++) comes along and reads the hex, converts it to bytes and decrypts it.</p> <p>The issue is apparently the C implementation correctly decrypts the text, but also keeps extra bytes at the end that are unnecessary.</p> <p>For example (not real values):</p> <pre><code>Java: encrypt("eric") -&gt; 1234567890FFFFFF1234567890FFFFFF (hex) Java: decrypt("1234567890FFFFFF1234567890FFFFFF") -&gt; "eric" C: decrypt("1234567890FFFFFF1234567890FFFFFF") -&gt; "eric XXXX XXXX XXXX" </code></pre> <p>I do not own the C decryption algorithm and the party using it has suggested I append a null terminator character <code>'\0'</code> to the Java bytes before encryption. My question is, would that work and should I even entertain that idea? </p> <p>Reading the first answer (while "unaccepted", it sounds correct to me) to the question <a href="https://stackoverflow.com/questions/1927380/padding-error-when-using-aes-encryption-in-java-and-decryption-in-c">Padding error when using AES encryption in Java and decryption in c</a>, an explicit encoding of the padding size seems to be the correct way to go about this.</p> <p>However, what if the string is encrypted in C and decrypted in C? Will the C encrypted string now have issues when decrypted in C, and removing the padding as if it were a Java encrypted string? Or would this be a non-issue?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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