Advertisement
Guest User

ING Mobile App Security

a guest
Nov 9th, 2011
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.42 KB | None | 0 0
  1. package com.ing.mobile.security;
  2.  
  3. import B;
  4. import com.ing.mobile.app.c.e;
  5. import com.ing.mobile.c.b;
  6. import com.ing.mobile.c.c;
  7. import java.io.UnsupportedEncodingException;
  8. import java.math.BigInteger;
  9. import java.security.InvalidAlgorithmParameterException;
  10. import java.security.InvalidKeyException;
  11. import java.security.KeyFactory;
  12. import java.security.KeyPair;
  13. import java.security.KeyPairGenerator;
  14. import java.security.MessageDigest;
  15. import java.security.NoSuchAlgorithmException;
  16. import java.security.NoSuchProviderException;
  17. import java.security.PrivateKey;
  18. import java.security.PublicKey;
  19. import java.security.SecureRandom;
  20. import java.security.Signature;
  21. import java.security.SignatureException;
  22. import java.security.interfaces.RSAPrivateKey;
  23. import java.security.interfaces.RSAPublicKey;
  24. import java.security.spec.RSAPrivateKeySpec;
  25. import java.security.spec.RSAPublicKeySpec;
  26. import java.util.StringTokenizer;
  27. import java.util.UUID;
  28. import javax.crypto.BadPaddingException;
  29. import javax.crypto.Cipher;
  30. import javax.crypto.IllegalBlockSizeException;
  31. import javax.crypto.KeyGenerator;
  32. import javax.crypto.Mac;
  33. import javax.crypto.NoSuchPaddingException;
  34. import javax.crypto.SecretKey;
  35. import javax.crypto.spec.IvParameterSpec;
  36. import javax.crypto.spec.SecretKeySpec;
  37.  
  38. public class CryptoServiceImpl
  39.   implements CryptoService
  40. {
  41.   private static String a = "CryptoServiceImpl";
  42.   private static final String b = "RSA/None/PKCS1Padding";
  43.   private static final int c = 2048;
  44.   private static final String d = "SHA1withRSA";
  45.   private static final String e = "AES";
  46.   private static final String f = "CBC";
  47.   private static final String g = "PKCS5Padding";
  48.   private static final int h = 128;
  49.   private static final String i = "SHA1";
  50.   private static final String j = "BC";
  51.   private static final SecureRandom k = new SecureRandom();
  52.   private static final String l = "HmacSHA1";
  53.   private static final IvParameterSpec m;
  54.  
  55.   static
  56.   {
  57.     byte[] arrayOfByte = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  58.     m = new IvParameterSpec(arrayOfByte);
  59.   }
  60.  
  61.   private final BigInteger[] c(String paramString, boolean paramBoolean)
  62.   {
  63.     StringTokenizer localStringTokenizer = new StringTokenizer(paramString, "|");
  64.     if (localStringTokenizer.countTokens() != 2)
  65.       throw new RuntimeException("The Key was serialized in the wrong way");
  66.     BigInteger localBigInteger1;
  67.     byte[] arrayOfByte2;
  68.     if (paramBoolean)
  69.     {
  70.       byte[] arrayOfByte1 = e.a(localStringTokenizer.nextToken().toCharArray());
  71.       localBigInteger1 = new BigInteger(arrayOfByte1);
  72.       arrayOfByte2 = e.a(localStringTokenizer.nextToken().toCharArray());
  73.     }
  74.     String str2;
  75.     for (BigInteger localBigInteger2 = new BigInteger(arrayOfByte2); ; localBigInteger2 = new BigInteger(str2))
  76.     {
  77.       BigInteger[] arrayOfBigInteger = new BigInteger[2];
  78.       arrayOfBigInteger[0] = localBigInteger1;
  79.       arrayOfBigInteger[1] = localBigInteger2;
  80.       return arrayOfBigInteger;
  81.       String str1 = localStringTokenizer.nextToken();
  82.       localBigInteger1 = new BigInteger(str1);
  83.       str2 = localStringTokenizer.nextToken();
  84.     }
  85.   }
  86.  
  87.   public String a(String paramString)
  88.   {
  89.     b localb2;
  90.     try
  91.     {
  92.       byte[] arrayOfByte = paramString.getBytes("UTF-8");
  93.       String str = e.c(MessageDigest.getInstance("SHA1").digest(arrayOfByte));
  94.       return str;
  95.     }
  96.     catch (UnsupportedEncodingException localUnsupportedEncodingException)
  97.     {
  98.       b localb1 = b.d;
  99.       throw new c(localb1, "900");
  100.     }
  101.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  102.     {
  103.       localb2 = b.c;
  104.     }
  105.     throw new c(localb2, "900");
  106.   }
  107.  
  108.   public String a(String paramString1, String paramString2)
  109.   {
  110.     b localb3;
  111.     try
  112.     {
  113.       Mac localMac = Mac.getInstance("HmacSHA1");
  114.       byte[] arrayOfByte1 = e.a(paramString2.toCharArray());
  115.       SecretKeySpec localSecretKeySpec = new SecretKeySpec(arrayOfByte1, "HmacSHA1");
  116.       localMac.init(localSecretKeySpec);
  117.       byte[] arrayOfByte2 = paramString1.getBytes("UTF-8");
  118.       char[] arrayOfChar = e.a(localMac.doFinal(arrayOfByte2));
  119.       String str = new String(arrayOfChar);
  120.       return str;
  121.     }
  122.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  123.     {
  124.       b localb1 = b.c;
  125.       throw new c(localb1, "900");
  126.     }
  127.     catch (InvalidKeyException localInvalidKeyException)
  128.     {
  129.       b localb2 = b.c;
  130.       throw new c(localb2, "900");
  131.     }
  132.     catch (UnsupportedEncodingException localUnsupportedEncodingException)
  133.     {
  134.       localb3 = b.c;
  135.     }
  136.     throw new c(localb3, "900");
  137.   }
  138.  
  139.   public String a(String paramString, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, byte[] paramArrayOfByte3)
  140.   {
  141.     b localb2;
  142.     try
  143.     {
  144.       byte[] arrayOfByte1 = paramString.getBytes("UTF-8");
  145.       this = (byte[])(byte[])paramArrayOfByte1.clone();
  146.       Object localObject = (byte[])(byte[])paramArrayOfByte2.clone();
  147.       int n = 0;
  148.       int i1 = this.length;
  149.       int i5;
  150.       if (n < i1)
  151.       {
  152.         int i2 = paramArrayOfByte3.length;
  153.         int i3;
  154.         int i4;
  155.         if (n < i2)
  156.         {
  157.           i3 = this[n];
  158.           i4 = paramArrayOfByte3[n];
  159.         }
  160.         for (i5 = i3 ^ i4; ; i5 = this[n])
  161.         {
  162.           int i6 = (byte)i5;
  163.           this[n] = i6;
  164.           n += 1;
  165.           break;
  166.         }
  167.       }
  168.       n = 0;
  169.       int i7 = localObject.length;
  170.       if (n < i7)
  171.       {
  172.         int i8 = paramArrayOfByte3.length;
  173.         int i9;
  174.         int i10;
  175.         if (n < i8)
  176.         {
  177.           i9 = localObject[n];
  178.           i10 = paramArrayOfByte3[n];
  179.         }
  180.         for (i5 = i9 ^ i10; ; i5 = localObject[n])
  181.         {
  182.           int i11 = (byte)i5;
  183.           localObject[n] = i11;
  184.           n += 1;
  185.           break;
  186.         }
  187.       }
  188.       int i12 = this.length;
  189.       int i13 = arrayOfByte1.length;
  190.       int i14 = i12 + i13;
  191.       int i15 = localObject.length;
  192.       byte[] arrayOfByte2 = new byte[i14 + i15];
  193.       int i16 = this.length;
  194.       System.arraycopy(this, 0, arrayOfByte2, 0, i16);
  195.       int i17 = this.length;
  196.       int i18 = arrayOfByte1.length;
  197.       System.arraycopy(arrayOfByte1, 0, arrayOfByte2, i17, i18);
  198.       int i19 = this.length;
  199.       int i20 = arrayOfByte1.length + i19;
  200.       int i21 = localObject.length;
  201.       System.arraycopy(localObject, 0, arrayOfByte2, i20, i21);
  202.       localObject = new String(arrayOfByte2, "US-ASCII");
  203.       return localObject;
  204.     }
  205.     catch (UnsupportedEncodingException localUnsupportedEncodingException)
  206.     {
  207.       b localb1 = b.c;
  208.       throw new c(localb1, "900");
  209.     }
  210.     catch (NullPointerException localNullPointerException)
  211.     {
  212.       localb2 = b.g;
  213.     }
  214.     throw new c(localb2, "900");
  215.   }
  216.  
  217.   public String a(PrivateKey paramPrivateKey, boolean paramBoolean)
  218.   {
  219.     RSAPrivateKey localRSAPrivateKey = (RSAPrivateKey)paramPrivateKey;
  220.     StringBuilder localStringBuilder2;
  221.     String str2;
  222.     if (paramBoolean)
  223.     {
  224.       StringBuilder localStringBuilder1 = new StringBuilder();
  225.       char[] arrayOfChar1 = e.a(localRSAPrivateKey.getModulus().toByteArray());
  226.       String str1 = new String(arrayOfChar1);
  227.       localStringBuilder2 = localStringBuilder1.append(str1).append("|");
  228.       char[] arrayOfChar2 = e.a(localRSAPrivateKey.getPrivateExponent().toByteArray());
  229.       str2 = new String(arrayOfChar2);
  230.     }
  231.     StringBuilder localStringBuilder4;
  232.     BigInteger localBigInteger2;
  233.     for (String str3 = str2; ; str3 = localBigInteger2)
  234.     {
  235.       return str3;
  236.       StringBuilder localStringBuilder3 = new StringBuilder();
  237.       BigInteger localBigInteger1 = localRSAPrivateKey.getModulus();
  238.       localStringBuilder4 = localStringBuilder3.append(localBigInteger1).append("|");
  239.       localBigInteger2 = localRSAPrivateKey.getPrivateExponent();
  240.     }
  241.   }
  242.  
  243.   public String a(PublicKey paramPublicKey, boolean paramBoolean)
  244.   {
  245.     RSAPublicKey localRSAPublicKey = (RSAPublicKey)paramPublicKey;
  246.     StringBuilder localStringBuilder2;
  247.     String str2;
  248.     if (paramBoolean)
  249.     {
  250.       StringBuilder localStringBuilder1 = new StringBuilder();
  251.       char[] arrayOfChar1 = e.a(localRSAPublicKey.getModulus().toByteArray());
  252.       String str1 = new String(arrayOfChar1);
  253.       localStringBuilder2 = localStringBuilder1.append(str1).append("|");
  254.       char[] arrayOfChar2 = e.a(localRSAPublicKey.getPublicExponent().toByteArray());
  255.       str2 = new String(arrayOfChar2);
  256.     }
  257.     StringBuilder localStringBuilder4;
  258.     BigInteger localBigInteger2;
  259.     for (String str3 = str2; ; str3 = localBigInteger2)
  260.     {
  261.       return str3;
  262.       StringBuilder localStringBuilder3 = new StringBuilder();
  263.       BigInteger localBigInteger1 = localRSAPublicKey.getModulus();
  264.       localStringBuilder4 = localStringBuilder3.append(localBigInteger1).append("|");
  265.       localBigInteger2 = localRSAPublicKey.getPublicExponent();
  266.     }
  267.   }
  268.  
  269.   public PublicKey a(String paramString, boolean paramBoolean)
  270.   {
  271.     BigInteger[] arrayOfBigInteger = c(paramString, paramBoolean);
  272.     try
  273.     {
  274.       KeyFactory localKeyFactory = KeyFactory.getInstance("RSA");
  275.       BigInteger localBigInteger1 = arrayOfBigInteger[0];
  276.       BigInteger localBigInteger2 = arrayOfBigInteger[1];
  277.       RSAPublicKeySpec localRSAPublicKeySpec = new RSAPublicKeySpec(localBigInteger1, localBigInteger2);
  278.       PublicKey localPublicKey = localKeyFactory.generatePublic(localRSAPublicKeySpec);
  279.       return localPublicKey;
  280.     }
  281.     catch (Exception localException)
  282.     {
  283.     }
  284.     throw new RuntimeException(localException);
  285.   }
  286.  
  287.   public boolean a(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, PublicKey paramPublicKey)
  288.   {
  289.     b localb4;
  290.     try
  291.     {
  292.       Signature localSignature = Signature.getInstance("SHA1withRSA", "BC");
  293.       localSignature.initVerify(paramPublicKey);
  294.       localSignature.update(paramArrayOfByte2);
  295.       boolean bool = localSignature.verify(paramArrayOfByte1);
  296.       return bool;
  297.     }
  298.     catch (SignatureException localSignatureException)
  299.     {
  300.       b localb1 = b.c;
  301.       throw new c(localb1, "900");
  302.     }
  303.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  304.     {
  305.       b localb2 = b.c;
  306.       throw new c(localb2, "900");
  307.     }
  308.     catch (NoSuchProviderException localNoSuchProviderException)
  309.     {
  310.       b localb3 = b.c;
  311.       throw new c(localb3, "900");
  312.     }
  313.     catch (InvalidKeyException localInvalidKeyException)
  314.     {
  315.       localb4 = b.c;
  316.     }
  317.     throw new c(localb4, "900");
  318.   }
  319.  
  320.   public byte[] a()
  321.   {
  322.     b localb2;
  323.     try
  324.     {
  325.       KeyGenerator localKeyGenerator = KeyGenerator.getInstance("AES", "BC");
  326.       localKeyGenerator.init(128);
  327.       byte[] arrayOfByte = localKeyGenerator.generateKey().getEncoded();
  328.       return arrayOfByte;
  329.     }
  330.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  331.     {
  332.       b localb1 = b.c;
  333.       throw new c(localb1, "900");
  334.     }
  335.     catch (NoSuchProviderException localNoSuchProviderException)
  336.     {
  337.       localb2 = b.c;
  338.     }
  339.     throw new c(localb2, "900");
  340.   }
  341.  
  342.   public byte[] a(int paramInt)
  343.   {
  344.     byte[] arrayOfByte = new byte[paramInt];
  345.     k.nextBytes(arrayOfByte);
  346.     return arrayOfByte;
  347.   }
  348.  
  349.   public byte[] a(byte[] paramArrayOfByte, PrivateKey paramPrivateKey)
  350.   {
  351.     b localb6;
  352.     try
  353.     {
  354.       Cipher localCipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
  355.       localCipher.init(2, paramPrivateKey);
  356.       byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte);
  357.       return arrayOfByte;
  358.     }
  359.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  360.     {
  361.       b localb1 = b.c;
  362.       throw new c(localb1, "900");
  363.     }
  364.     catch (NoSuchProviderException localNoSuchProviderException)
  365.     {
  366.       b localb2 = b.c;
  367.       throw new c(localb2, "900");
  368.     }
  369.     catch (NoSuchPaddingException localNoSuchPaddingException)
  370.     {
  371.       b localb3 = b.c;
  372.       throw new c(localb3, "900");
  373.     }
  374.     catch (IllegalBlockSizeException localIllegalBlockSizeException)
  375.     {
  376.       b localb4 = b.c;
  377.       throw new c(localb4, "900");
  378.     }
  379.     catch (BadPaddingException localBadPaddingException)
  380.     {
  381.       b localb5 = b.c;
  382.       throw new c(localb5, "900");
  383.     }
  384.     catch (InvalidKeyException localInvalidKeyException)
  385.     {
  386.       localb6 = b.c;
  387.     }
  388.     throw new c(localb6, "900");
  389.   }
  390.  
  391.   public byte[] a(byte[] paramArrayOfByte, PublicKey paramPublicKey)
  392.   {
  393.     b localb6;
  394.     try
  395.     {
  396.       Cipher localCipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
  397.       localCipher.init(1, paramPublicKey);
  398.       byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte);
  399.       return arrayOfByte;
  400.     }
  401.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  402.     {
  403.       b localb1 = b.c;
  404.       throw new c(localb1, "900");
  405.     }
  406.     catch (NoSuchProviderException localNoSuchProviderException)
  407.     {
  408.       b localb2 = b.c;
  409.       throw new c(localb2, "900");
  410.     }
  411.     catch (NoSuchPaddingException localNoSuchPaddingException)
  412.     {
  413.       b localb3 = b.c;
  414.       throw new c(localb3, "900");
  415.     }
  416.     catch (IllegalBlockSizeException localIllegalBlockSizeException)
  417.     {
  418.       b localb4 = b.c;
  419.       throw new c(localb4, "900");
  420.     }
  421.     catch (BadPaddingException localBadPaddingException)
  422.     {
  423.       b localb5 = b.c;
  424.       throw new c(localb5, "900");
  425.     }
  426.     catch (InvalidKeyException localInvalidKeyException)
  427.     {
  428.       localb6 = b.c;
  429.     }
  430.     throw new c(localb6, "900");
  431.   }
  432.  
  433.   public byte[] a(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
  434.   {
  435.     SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
  436.     b localb7;
  437.     try
  438.     {
  439.       Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
  440.       IvParameterSpec localIvParameterSpec = m;
  441.       localCipher.init(2, localSecretKeySpec, localIvParameterSpec);
  442.       byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte2);
  443.       return arrayOfByte;
  444.     }
  445.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  446.     {
  447.       b localb1 = b.c;
  448.       throw new c(localb1, "900");
  449.     }
  450.     catch (NoSuchProviderException localNoSuchProviderException)
  451.     {
  452.       b localb2 = b.c;
  453.       throw new c(localb2, "900");
  454.     }
  455.     catch (NoSuchPaddingException localNoSuchPaddingException)
  456.     {
  457.       b localb3 = b.c;
  458.       throw new c(localb3, "900");
  459.     }
  460.     catch (IllegalBlockSizeException localIllegalBlockSizeException)
  461.     {
  462.       b localb4 = b.c;
  463.       throw new c(localb4, "900");
  464.     }
  465.     catch (BadPaddingException localBadPaddingException)
  466.     {
  467.       b localb5 = b.c;
  468.       throw new c(localb5, "900");
  469.     }
  470.     catch (InvalidKeyException localInvalidKeyException)
  471.     {
  472.       b localb6 = b.c;
  473.       throw new c(localb6, "900");
  474.     }
  475.     catch (InvalidAlgorithmParameterException localInvalidAlgorithmParameterException)
  476.     {
  477.       localb7 = b.c;
  478.     }
  479.     throw new c(localb7, "900");
  480.   }
  481.  
  482.   public String b()
  483.   {
  484.     return UUID.randomUUID().toString();
  485.   }
  486.  
  487.   public PrivateKey b(String paramString, boolean paramBoolean)
  488.   {
  489.     BigInteger[] arrayOfBigInteger = c(paramString, paramBoolean);
  490.     try
  491.     {
  492.       KeyFactory localKeyFactory = KeyFactory.getInstance("RSA");
  493.       BigInteger localBigInteger1 = arrayOfBigInteger[0];
  494.       BigInteger localBigInteger2 = arrayOfBigInteger[1];
  495.       RSAPrivateKeySpec localRSAPrivateKeySpec = new RSAPrivateKeySpec(localBigInteger1, localBigInteger2);
  496.       PrivateKey localPrivateKey = localKeyFactory.generatePrivate(localRSAPrivateKeySpec);
  497.       return localPrivateKey;
  498.     }
  499.     catch (Exception localException)
  500.     {
  501.     }
  502.     throw new RuntimeException(localException);
  503.   }
  504.  
  505.   public byte[] b(byte[] paramArrayOfByte, PrivateKey paramPrivateKey)
  506.   {
  507.     b localb4;
  508.     try
  509.     {
  510.       Signature localSignature = Signature.getInstance("SHA1withRSA", "BC");
  511.       localSignature.initSign(paramPrivateKey);
  512.       localSignature.update(paramArrayOfByte);
  513.       byte[] arrayOfByte = localSignature.sign();
  514.       return arrayOfByte;
  515.     }
  516.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  517.     {
  518.       b localb1 = b.c;
  519.       throw new c(localb1, "900");
  520.     }
  521.     catch (NoSuchProviderException localNoSuchProviderException)
  522.     {
  523.       b localb2 = b.c;
  524.       throw new c(localb2, "900");
  525.     }
  526.     catch (InvalidKeyException localInvalidKeyException)
  527.     {
  528.       b localb3 = b.c;
  529.       throw new c(localb3, "900");
  530.     }
  531.     catch (SignatureException localSignatureException)
  532.     {
  533.       localb4 = b.c;
  534.     }
  535.     throw new c(localb4, "900");
  536.   }
  537.  
  538.   public byte[] b(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
  539.   {
  540.     b localb6;
  541.     try
  542.     {
  543.       SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
  544.       Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
  545.       IvParameterSpec localIvParameterSpec = m;
  546.       localCipher.init(1, localSecretKeySpec, localIvParameterSpec);
  547.       byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte2);
  548.       return arrayOfByte;
  549.     }
  550.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  551.     {
  552.       b localb1 = b.c;
  553.       throw new c(localb1, "900");
  554.     }
  555.     catch (NoSuchPaddingException localNoSuchPaddingException)
  556.     {
  557.       b localb2 = b.c;
  558.       throw new c(localb2, "900");
  559.     }
  560.     catch (IllegalBlockSizeException localIllegalBlockSizeException)
  561.     {
  562.       b localb3 = b.c;
  563.       throw new c(localb3, "900");
  564.     }
  565.     catch (BadPaddingException localBadPaddingException)
  566.     {
  567.       b localb4 = b.c;
  568.       throw new c(localb4, "900");
  569.     }
  570.     catch (InvalidKeyException localInvalidKeyException)
  571.     {
  572.       b localb5 = b.c;
  573.       throw new c(localb5, "900");
  574.     }
  575.     catch (InvalidAlgorithmParameterException localInvalidAlgorithmParameterException)
  576.     {
  577.       localb6 = b.c;
  578.     }
  579.     throw new c(localb6, "900");
  580.   }
  581.  
  582.   public KeyPair c()
  583.   {
  584.     b localb2;
  585.     try
  586.     {
  587.       KeyPairGenerator localKeyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
  588.       localKeyPairGenerator.initialize(2048);
  589.       KeyPair localKeyPair = localKeyPairGenerator.generateKeyPair();
  590.       return localKeyPair;
  591.     }
  592.     catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
  593.     {
  594.       b localb1 = b.c;
  595.       throw new c(localb1, "900");
  596.     }
  597.     catch (NoSuchProviderException localNoSuchProviderException)
  598.     {
  599.       localb2 = b.c;
  600.     }
  601.     throw new c(localb2, "900");
  602.   }
  603. }
  604.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement