Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pt.ven.decryptAbsolut;
- import java.security.GeneralSecurityException;
- import java.security.InvalidKeyException;
- import java.security.KeyException;
- import java.security.NoSuchAlgorithmException;
- import java.security.spec.InvalidKeySpecException;
- import java.util.zip.CRC32;
- import javax.crypto.Cipher;
- import javax.crypto.SecretKeyFactory;
- import javax.crypto.spec.DESedeKeySpec;
- import javax.crypto.spec.IvParameterSpec;
- import java.io.*;
- import java.security.SecureRandom;
- import java.util.Hashtable;
- import java.util.UUID;
- import javax.crypto.CipherInputStream;
- import javax.crypto.CipherOutputStream;
- public class main {
- static Hashtable c;
- /**
- * @param args
- */
- public static void main(String[] args) {
- try {
- decryptFile("settings"); // file to decode
- } catch (KeyException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (GeneralSecurityException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static Cipher getCipher(byte abyte0[], int i, String s, String s1) throws InvalidKeyException, GeneralSecurityException, NoSuchAlgorithmException
- {
- String s2 = "DESede";
- int j = s.indexOf("/");
- if(j != -1)
- s2 = s.substring(0, j);
- DESedeKeySpec desedekeyspec = new DESedeKeySpec(abyte0);
- javax.crypto.SecretKey secretkey = SecretKeyFactory.getInstance(s2).generateSecret(desedekeyspec);
- IvParameterSpec ivparameterspec = new IvParameterSpec(a(s1));
- Cipher cipher = Cipher.getInstance(s);
- cipher.init(i, secretkey, ivparameterspec);
- return cipher;
- }
- public static byte[] a(String s)
- {
- byte abyte0[] = new byte[s.length()];
- int i = 0;
- do
- {
- if(i >= s.length())
- {
- CRC32 crc32 = new CRC32();
- crc32.update(abyte0, 0, abyte0.length);
- long l = 0xffffffffL & crc32.getValue();
- byte abyte1[] = new byte[8];
- abyte1[0] = 0;
- abyte1[1] = 0;
- abyte1[2] = 0;
- abyte1[3] = 0;
- abyte1[4] = (byte)(int)((0xffffffffff000000L & l) >> 24);
- abyte1[5] = (byte)(int)((0xff0000L & l) >> 16);
- abyte1[6] = (byte)(int)((65280L & l) >> 8);
- abyte1[7] = (byte)(int)(l & 255L);
- return abyte1;
- }
- abyte0[i] = (byte)s.charAt(i);
- i++;
- } while(true);
- }
- public static void decryptFile(String filename) throws IOException, KeyException, Exception, GeneralSecurityException
- {
- FileInputStream fileinputstream;
- ObjectInputStream objectinputstream;
- CipherInputStream cipherinputstream1;
- byte first_36_bytes[];
- Hashtable hashtable;
- byte first_24_bytes[];
- fileinputstream = new FileInputStream(filename);
- first_36_bytes = new byte[36];
- fileinputstream.read(first_36_bytes, 0, 36);
- first_24_bytes = new byte[24];
- fileinputstream.read(first_24_bytes, 0, 24);
- cipherinputstream1 = new CipherInputStream(fileinputstream, getCipher(first_24_bytes, 2, "DESede/CBC/PKCS5Padding", new String(first_36_bytes)));
- objectinputstream = new ObjectInputStream(cipherinputstream1);
- hashtable = (Hashtable) objectinputstream.readObject();
- c = hashtable;
- System.out.println(hashtable); // prints file to system.out
- objectinputstream.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement