Advertisement
Guest User

Untitled

a guest
May 16th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.63 KB | None | 0 0
  1. package pt.ven.decryptAbsolut;
  2.  
  3. import java.security.GeneralSecurityException;
  4. import java.security.InvalidKeyException;
  5. import java.security.KeyException;
  6. import java.security.NoSuchAlgorithmException;
  7. import java.security.spec.InvalidKeySpecException;
  8. import java.util.zip.CRC32;
  9. import javax.crypto.Cipher;
  10. import javax.crypto.SecretKeyFactory;
  11. import javax.crypto.spec.DESedeKeySpec;
  12. import javax.crypto.spec.IvParameterSpec;
  13.  
  14. import java.io.*;
  15. import java.security.SecureRandom;
  16. import java.util.Hashtable;
  17. import java.util.UUID;
  18. import javax.crypto.CipherInputStream;
  19. import javax.crypto.CipherOutputStream;
  20.  
  21.  
  22.  
  23.  
  24. public class main {
  25.    
  26.     static Hashtable c;
  27.  
  28.     /**
  29.      * @param args
  30.      */
  31.     public static void main(String[] args) {
  32.         try {
  33.             decryptFile("settings"); // file to decode
  34.         } catch (KeyException e) {
  35.             e.printStackTrace();
  36.         } catch (IOException e) {
  37.             e.printStackTrace();
  38.         } catch (GeneralSecurityException e) {
  39.             e.printStackTrace();
  40.         } catch (Exception e) {
  41.             e.printStackTrace();
  42.         }
  43.        
  44.  
  45.     }
  46.    
  47.     public static Cipher getCipher(byte abyte0[], int i, String s, String s1) throws InvalidKeyException, GeneralSecurityException, NoSuchAlgorithmException
  48.     {
  49.         String s2 = "DESede";
  50.         int j = s.indexOf("/");
  51.         if(j != -1)
  52.             s2 = s.substring(0, j);
  53.         DESedeKeySpec desedekeyspec = new DESedeKeySpec(abyte0);
  54.         javax.crypto.SecretKey secretkey = SecretKeyFactory.getInstance(s2).generateSecret(desedekeyspec);
  55.         IvParameterSpec ivparameterspec = new IvParameterSpec(a(s1));
  56.         Cipher cipher = Cipher.getInstance(s);
  57.         cipher.init(i, secretkey, ivparameterspec);
  58.         return cipher;
  59.     }
  60.    
  61.     public static byte[] a(String s)
  62.     {
  63.         byte abyte0[] = new byte[s.length()];
  64.         int i = 0;
  65.         do
  66.         {
  67.             if(i >= s.length())
  68.             {
  69.                 CRC32 crc32 = new CRC32();
  70.                 crc32.update(abyte0, 0, abyte0.length);
  71.                 long l = 0xffffffffL & crc32.getValue();
  72.                 byte abyte1[] = new byte[8];
  73.                 abyte1[0] = 0;
  74.                 abyte1[1] = 0;
  75.                 abyte1[2] = 0;
  76.                 abyte1[3] = 0;
  77.                 abyte1[4] = (byte)(int)((0xffffffffff000000L & l) >> 24);
  78.                 abyte1[5] = (byte)(int)((0xff0000L & l) >> 16);
  79.                 abyte1[6] = (byte)(int)((65280L & l) >> 8);
  80.                 abyte1[7] = (byte)(int)(l & 255L);
  81.                 return abyte1;
  82.             }
  83.             abyte0[i] = (byte)s.charAt(i);
  84.             i++;
  85.         } while(true);
  86.     }
  87.    
  88.     public static void decryptFile(String filename) throws IOException, KeyException, Exception, GeneralSecurityException
  89.     {
  90.         FileInputStream fileinputstream;
  91.         ObjectInputStream objectinputstream;
  92.         CipherInputStream cipherinputstream1;
  93.         byte first_36_bytes[];
  94.         Hashtable hashtable;
  95.         byte first_24_bytes[];
  96.         fileinputstream = new FileInputStream(filename);                        
  97.         first_36_bytes = new byte[36];
  98.         fileinputstream.read(first_36_bytes, 0, 36);
  99.         first_24_bytes = new byte[24];
  100.         fileinputstream.read(first_24_bytes, 0, 24);
  101.         cipherinputstream1 = new CipherInputStream(fileinputstream, getCipher(first_24_bytes, 2, "DESede/CBC/PKCS5Padding", new String(first_36_bytes)));  
  102.         objectinputstream = new ObjectInputStream(cipherinputstream1);
  103.         hashtable = (Hashtable) objectinputstream.readObject();
  104.         c = hashtable;
  105.         System.out.println(hashtable); // prints file to system.out
  106.         objectinputstream.close();
  107.        
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement