Advertisement
Guest User

OpenVPN Android password remind extract password decode pass

a guest
Nov 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.72 KB | None | 0 0
  1. // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.geocities.com/kpdus/jad.html
  3. // Decompiler options: braces fieldsfirst space lnc
  4.  
  5. package net.openvpn.openvpn;
  6.  
  7. import java.util.Base64;
  8. import java.util.Arrays;
  9. import java.util.Iterator;
  10. import java.util.Map;
  11. import java.util.Set;
  12. import javax.crypto.Cipher;
  13. import javax.crypto.SecretKey;
  14. import javax.crypto.SecretKeyFactory;
  15. import javax.crypto.spec.IvParameterSpec;
  16. import javax.crypto.spec.PBEKeySpec;
  17. import javax.crypto.spec.SecretKeySpec;
  18.  
  19. public class PasswordUtil
  20. {
  21.  
  22.     private static final String TAG = "PasswordUtil";
  23.     private String cipherName;
  24.     private IvParameterSpec ivParms;
  25.     private String prefPrefix;
  26.     private byte salt[];
  27.     private SecretKey secret;
  28.     private String _salt;
  29.  
  30.     PasswordUtil(String l_salt)
  31.     {
  32.         _salt = l_salt;
  33.         prefPrefix = "pwdv1";
  34.         regenerate(false);
  35.     }
  36.  
  37.     private void check_salt()
  38.     {
  39.         byte l_salt[] = get_salt();
  40.         if (l_salt != null && salt != null && !Arrays.equals(l_salt, salt))
  41.         {
  42.             regenerate(false);
  43.         }
  44.     }
  45.  
  46.     private String en(String s)
  47.     {
  48.         check_salt();
  49.         if (s == null || secret == null || prefPrefix == null)
  50.         {
  51.             return null;
  52.         }
  53.         String encoded;
  54.         try {
  55.           Cipher cipher = Cipher.getInstance(cipherName);
  56.           cipher.init(1, secret, ivParms);
  57.           encoded = Base64.getEncoder().encodeToString(cipher.doFinal(s.getBytes("UTF-8")));
  58.           return encoded;
  59.         } catch (Exception e) {
  60.           return null;
  61.         }
  62.     }
  63.  
  64.     private byte[] get_salt()
  65.     {
  66.       byte[] salt_bytes = Base64.getDecoder().decode(_salt);
  67.       return salt_bytes;
  68.     }
  69.  
  70.     void regenerate(boolean flag)
  71.     {
  72.         cipherName = "AES/CBC/PKCS5Padding";
  73.         byte key_block[] = {
  74.             -42, -31, -117, 101, 25, 119, 127, 37, 121, -54,
  75.             46, 49, -35, -48, -72, 97
  76.         };
  77.         salt = get_salt();
  78.         if (salt != null)
  79.         {
  80.             try
  81.             {
  82.                 secret = new SecretKeySpec(SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec("It was a bright cold day in April, and the clocks were striking thirteen. Winston Smith, his chin nuzzled into his breast in an effort to escape the vile wind, slipped quickly through the glass doors of Victory Mansions, though not quickly enough to prevent a swirl of gritty dust from entering along with him.".toCharArray(), salt, 16, 128)).getEncoded(), "AES");
  83.                 ivParms = new IvParameterSpec(key_block);
  84.                 return;
  85.             }
  86.             catch (Exception exception)
  87.             {
  88.  
  89.             }
  90.         }
  91.         secret = null;
  92.         prefPrefix = null;
  93.     }
  94.  
  95.     private String de(String s)
  96.     {
  97.         check_salt();
  98.         if (s == null || secret == null || prefPrefix == null)
  99.         {
  100.           System.out.println("de(1)");
  101.             return null;
  102.         }
  103.         String plaintext;
  104.         try {
  105.           byte pass_bytes[] = Base64.getDecoder().decode(s);
  106.           Cipher cipher = Cipher.getInstance(cipherName);
  107.           cipher.init(2, secret, ivParms);
  108.           plaintext = new String(cipher.doFinal(pass_bytes), "UTF-8");
  109.           return plaintext;
  110.         } catch (Exception e) {
  111.           System.out.println("de(2): " + e.toString());
  112.           return null;
  113.         }
  114.     }
  115.  
  116.    
  117.     public static void main(String[] args) {
  118.       PasswordUtil pu = new PasswordUtil("BwR1k1P9GZZ30FP87ExqBw==");
  119.       System.out.println(pu.de("rC6MoRJ7cDAGuMb6Pjs1lQ=="));
  120.       System.out.println(pu.de("HBZjfOchOx3y/5RQrkHxDA=="));
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement