Now here is a working code:
encrypt:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class Encrypting {
Cipher ecipher;
Encrypting(Key key) {
byte[] iv = new byte[]{
(byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c,
(byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99
};
AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
try {
ecipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
}
catch (java.security.InvalidAlgorithmParameterException e) {}
catch (javax.crypto.NoSuchPaddingException e) {}
catch (java.security.NoSuchAlgorithmException e) {}
catch (java.security.InvalidKeyException e) {}
}
byte[] buf = new byte[1024];
public void encrypt(InputStream in, OutputStream out) {
try {
out = new CipherOutputStream(out, ecipher);
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
}
catch (java.io.IOException e) {}
}
public static void main(String args[]){
try {
Key k = new SecretKeySpec( "01234567".getBytes(), "DES" );
Encrypting encrypter = new Encrypting(k);
encrypter.encrypt(new FileInputStream("input.jpg"),
new FileOutputStream("output.jpg"));
} catch (Exception e) {}
}
}
and decrypting:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class Decrypting {
Cipher dcipher;
Decrypting(Key key){
byte[] iv = new byte[]{
(byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c,
(byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99
};
AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
try {
dcipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
}
catch (java.security.InvalidAlgorithmParameterException e) {}
catch (javax.crypto.NoSuchPaddingException e) {}
catch (java.security.NoSuchAlgorithmException e) {}
catch (java.security.InvalidKeyException e) {}
}
byte[] buf = new byte[1024];
public void decrypt(InputStream in, OutputStream out) {
try {
// Bytes read from in will be decrypted
in = new CipherInputStream(in, dcipher);
// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
} catch (java.io.IOException e) {
}
}
public static void main(String args[]){
try {
Key k = new SecretKeySpec( "01234567".getBytes(), "DES" );
Decrypting decrypter = new Decrypting(k);
decrypter.decrypt(new FileInputStream("output.jpg"),
new FileOutputStream("outputDEC.jpg"));
} catch (Exception e) {}
}
}
Now my input Pic has
8460668 Bytes,…
my encrypted Pic has
8460672 Bytes…
and the decrypted Pic has
8460668 Bytes
What do you think?
Is this encryption efficient enough to hold gamers modify games?
Sorry for my wrong Post!
could any mod please move this topic to Newless Clubies?