Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.security.InvalidAlgorithmParameterException: in RC6 as well as RC2
    text
    copied!<p>I'm new to security, and I tried a lot to remove the exception (below the code). Both the RC2 and RC6 ciphers are giving this exception. The input should be a 128 bit <code>String</code> and a key of 128 bits, the output should be 128 bits cipher text.</p> <pre><code>import java.security.spec.AlgorithmParameterSpec; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.util.*; public class RC2Encrypt { public static void main(String args []) throws Exception { Scanner s=new Scanner(System.in); System.out.println("Enter PlainTextString:"); String input=s.nextLine(); System.out.println(); System.out.println("Enter 16 digit key:"); String strPassword=s.nextLine(); SecretKeySpec key = new SecretKeySpec(strPassword.getBytes(), "RC2"); AlgorithmParameterSpec paramSpec = new IvParameterSpec(strPassword.getBytes()); Cipher cipher = Cipher.getInstance("RC2"); cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); byte[] encrypted = cipher.doFinal(input.getBytes()); String b1 = new String(encrypted); System.out.println("Original string: " + input); System.out.println("Encrypted string: " + b1); } } </code></pre> <hr> <p>This will generate the following exception:</p> <pre><code>Exception in thread "main" java.security.InvalidAlgorithmParameterException: Wrong IV length: must be 8 bytes long at com.sun.crypto.provider.SunJCE_f.a(DashoA13*..) at com.sun.crypto.provider.RC2Cipher.engineInit(DashoA13*..) at javax.crypto.Cipher.a(DashoA13*..) at javax.crypto.Cipher.a(DashoA13*..) at javax.crypto.Cipher.init(DashoA13*..) at javax.crypto.Cipher.init(DashoA13*..) at RC2Encrypt.main(RC2Encrypt.java:40) </code></pre>
 

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