hi solve thisc.ragupathi December 3, 2011 at 3:54 PM
i write this code on jave
import java.security.Security;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.lang.SecurityException;
/**
* Basic symmetric encryption example with padding and CBC using DES
*/
public class NewClass1
{
public static void main(String[] args) throws Exception
{
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
byte[] input = "harivardhanan".getBytes();
byte[] keyBytes = new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd,
(byte) 0xef };
byte[] ivBytes = new byte[] { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
SecretKeySpec key = new SecretKeySpec(keyBytes, "DES");
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS7Padding", "BC");
System.out.println("input : " + new String(input));
// encryption pass
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec);
byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
System.out.println("input.length"+input.length);
int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
System.out.println("cipher: " + new String(cipherText) + " bytes: " + ctLength);
// decryption pass
cipher.init(Cipher.DECRYPT_MODE, key, ivSpec);
byte[] plainText = new byte[cipher.getOutputSize(ctLength)];
int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0);
ptLength += cipher.doFinal(plainText, ptLength);
System.out.println("plain : " + new String(plainText) + " bytes: " + ptLength);
if(input.equals(plainText))
System.out.println("equal");
}
}
then this type of exception will appear
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
at newpackage.NewClass1.main(NewClass1.java:27)
Java Result: 1
hi solve thisc.ragupathi December 3, 2011 at 4:00 PM
how can i solve this problem:
Exception in thread"AWT-EventQueue-0" java.lang.UnsupportedClassVersionError:s
impleProtector:Unsupported major-minor Version 51.0
simplegaffar August 22, 2011 at 3:26 PM
simple and best example of vector
hi solve thisc.ragupathi December 3, 2011 at 3:54 PM
i write this code on jave import java.security.Security; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.lang.SecurityException; /** * Basic symmetric encryption example with padding and CBC using DES */ public class NewClass1 { public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); byte[] input = "harivardhanan".getBytes(); byte[] keyBytes = new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef }; byte[] ivBytes = new byte[] { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 }; SecretKeySpec key = new SecretKeySpec(keyBytes, "DES"); IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); Cipher cipher = Cipher.getInstance("DES/CBC/PKCS7Padding", "BC"); System.out.println("input : " + new String(input)); // encryption pass cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); byte[] cipherText = new byte[cipher.getOutputSize(input.length)]; System.out.println("input.length"+input.length); int ctLength = cipher.update(input, 0, input.length, cipherText, 0); ctLength += cipher.doFinal(cipherText, ctLength); System.out.println("cipher: " + new String(cipherText) + " bytes: " + ctLength); // decryption pass cipher.init(Cipher.DECRYPT_MODE, key, ivSpec); byte[] plainText = new byte[cipher.getOutputSize(ctLength)]; int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0); ptLength += cipher.doFinal(plainText, ptLength); System.out.println("plain : " + new String(plainText) + " bytes: " + ptLength); if(input.equals(plainText)) System.out.println("equal"); } } then this type of exception will appear Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any> at newpackage.NewClass1.main(NewClass1.java:27) Java Result: 1
hi solve thisc.ragupathi December 3, 2011 at 4:00 PM
how can i solve this problem: Exception in thread"AWT-EventQueue-0" java.lang.UnsupportedClassVersionError:s impleProtector:Unsupported major-minor Version 51.0
javaBhavin July 8, 2012 at 3:45 PM
thanks for helping.....god & easy understanding for vector in java..nice....
Post your Comment