Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ing.mobile.security;
- import B;
- import com.ing.mobile.app.c.e;
- import com.ing.mobile.c.b;
- import com.ing.mobile.c.c;
- import java.io.UnsupportedEncodingException;
- import java.math.BigInteger;
- import java.security.InvalidAlgorithmParameterException;
- import java.security.InvalidKeyException;
- import java.security.KeyFactory;
- import java.security.KeyPair;
- import java.security.KeyPairGenerator;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.security.NoSuchProviderException;
- import java.security.PrivateKey;
- import java.security.PublicKey;
- import java.security.SecureRandom;
- import java.security.Signature;
- import java.security.SignatureException;
- import java.security.interfaces.RSAPrivateKey;
- import java.security.interfaces.RSAPublicKey;
- import java.security.spec.RSAPrivateKeySpec;
- import java.security.spec.RSAPublicKeySpec;
- import java.util.StringTokenizer;
- import java.util.UUID;
- import javax.crypto.BadPaddingException;
- import javax.crypto.Cipher;
- import javax.crypto.IllegalBlockSizeException;
- import javax.crypto.KeyGenerator;
- import javax.crypto.Mac;
- import javax.crypto.NoSuchPaddingException;
- import javax.crypto.SecretKey;
- import javax.crypto.spec.IvParameterSpec;
- import javax.crypto.spec.SecretKeySpec;
- public class CryptoServiceImpl
- implements CryptoService
- {
- private static String a = "CryptoServiceImpl";
- private static final String b = "RSA/None/PKCS1Padding";
- private static final int c = 2048;
- private static final String d = "SHA1withRSA";
- private static final String e = "AES";
- private static final String f = "CBC";
- private static final String g = "PKCS5Padding";
- private static final int h = 128;
- private static final String i = "SHA1";
- private static final String j = "BC";
- private static final SecureRandom k = new SecureRandom();
- private static final String l = "HmacSHA1";
- private static final IvParameterSpec m;
- static
- {
- byte[] arrayOfByte = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- m = new IvParameterSpec(arrayOfByte);
- }
- private final BigInteger[] c(String paramString, boolean paramBoolean)
- {
- StringTokenizer localStringTokenizer = new StringTokenizer(paramString, "|");
- if (localStringTokenizer.countTokens() != 2)
- throw new RuntimeException("The Key was serialized in the wrong way");
- BigInteger localBigInteger1;
- byte[] arrayOfByte2;
- if (paramBoolean)
- {
- byte[] arrayOfByte1 = e.a(localStringTokenizer.nextToken().toCharArray());
- localBigInteger1 = new BigInteger(arrayOfByte1);
- arrayOfByte2 = e.a(localStringTokenizer.nextToken().toCharArray());
- }
- String str2;
- for (BigInteger localBigInteger2 = new BigInteger(arrayOfByte2); ; localBigInteger2 = new BigInteger(str2))
- {
- BigInteger[] arrayOfBigInteger = new BigInteger[2];
- arrayOfBigInteger[0] = localBigInteger1;
- arrayOfBigInteger[1] = localBigInteger2;
- return arrayOfBigInteger;
- String str1 = localStringTokenizer.nextToken();
- localBigInteger1 = new BigInteger(str1);
- str2 = localStringTokenizer.nextToken();
- }
- }
- public String a(String paramString)
- {
- b localb2;
- try
- {
- byte[] arrayOfByte = paramString.getBytes("UTF-8");
- String str = e.c(MessageDigest.getInstance("SHA1").digest(arrayOfByte));
- return str;
- }
- catch (UnsupportedEncodingException localUnsupportedEncodingException)
- {
- b localb1 = b.d;
- throw new c(localb1, "900");
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- localb2 = b.c;
- }
- throw new c(localb2, "900");
- }
- public String a(String paramString1, String paramString2)
- {
- b localb3;
- try
- {
- Mac localMac = Mac.getInstance("HmacSHA1");
- byte[] arrayOfByte1 = e.a(paramString2.toCharArray());
- SecretKeySpec localSecretKeySpec = new SecretKeySpec(arrayOfByte1, "HmacSHA1");
- localMac.init(localSecretKeySpec);
- byte[] arrayOfByte2 = paramString1.getBytes("UTF-8");
- char[] arrayOfChar = e.a(localMac.doFinal(arrayOfByte2));
- String str = new String(arrayOfChar);
- return str;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (InvalidKeyException localInvalidKeyException)
- {
- b localb2 = b.c;
- throw new c(localb2, "900");
- }
- catch (UnsupportedEncodingException localUnsupportedEncodingException)
- {
- localb3 = b.c;
- }
- throw new c(localb3, "900");
- }
- public String a(String paramString, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, byte[] paramArrayOfByte3)
- {
- b localb2;
- try
- {
- byte[] arrayOfByte1 = paramString.getBytes("UTF-8");
- this = (byte[])(byte[])paramArrayOfByte1.clone();
- Object localObject = (byte[])(byte[])paramArrayOfByte2.clone();
- int n = 0;
- int i1 = this.length;
- int i5;
- if (n < i1)
- {
- int i2 = paramArrayOfByte3.length;
- int i3;
- int i4;
- if (n < i2)
- {
- i3 = this[n];
- i4 = paramArrayOfByte3[n];
- }
- for (i5 = i3 ^ i4; ; i5 = this[n])
- {
- int i6 = (byte)i5;
- this[n] = i6;
- n += 1;
- break;
- }
- }
- n = 0;
- int i7 = localObject.length;
- if (n < i7)
- {
- int i8 = paramArrayOfByte3.length;
- int i9;
- int i10;
- if (n < i8)
- {
- i9 = localObject[n];
- i10 = paramArrayOfByte3[n];
- }
- for (i5 = i9 ^ i10; ; i5 = localObject[n])
- {
- int i11 = (byte)i5;
- localObject[n] = i11;
- n += 1;
- break;
- }
- }
- int i12 = this.length;
- int i13 = arrayOfByte1.length;
- int i14 = i12 + i13;
- int i15 = localObject.length;
- byte[] arrayOfByte2 = new byte[i14 + i15];
- int i16 = this.length;
- System.arraycopy(this, 0, arrayOfByte2, 0, i16);
- int i17 = this.length;
- int i18 = arrayOfByte1.length;
- System.arraycopy(arrayOfByte1, 0, arrayOfByte2, i17, i18);
- int i19 = this.length;
- int i20 = arrayOfByte1.length + i19;
- int i21 = localObject.length;
- System.arraycopy(localObject, 0, arrayOfByte2, i20, i21);
- localObject = new String(arrayOfByte2, "US-ASCII");
- return localObject;
- }
- catch (UnsupportedEncodingException localUnsupportedEncodingException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NullPointerException localNullPointerException)
- {
- localb2 = b.g;
- }
- throw new c(localb2, "900");
- }
- public String a(PrivateKey paramPrivateKey, boolean paramBoolean)
- {
- RSAPrivateKey localRSAPrivateKey = (RSAPrivateKey)paramPrivateKey;
- StringBuilder localStringBuilder2;
- String str2;
- if (paramBoolean)
- {
- StringBuilder localStringBuilder1 = new StringBuilder();
- char[] arrayOfChar1 = e.a(localRSAPrivateKey.getModulus().toByteArray());
- String str1 = new String(arrayOfChar1);
- localStringBuilder2 = localStringBuilder1.append(str1).append("|");
- char[] arrayOfChar2 = e.a(localRSAPrivateKey.getPrivateExponent().toByteArray());
- str2 = new String(arrayOfChar2);
- }
- StringBuilder localStringBuilder4;
- BigInteger localBigInteger2;
- for (String str3 = str2; ; str3 = localBigInteger2)
- {
- return str3;
- StringBuilder localStringBuilder3 = new StringBuilder();
- BigInteger localBigInteger1 = localRSAPrivateKey.getModulus();
- localStringBuilder4 = localStringBuilder3.append(localBigInteger1).append("|");
- localBigInteger2 = localRSAPrivateKey.getPrivateExponent();
- }
- }
- public String a(PublicKey paramPublicKey, boolean paramBoolean)
- {
- RSAPublicKey localRSAPublicKey = (RSAPublicKey)paramPublicKey;
- StringBuilder localStringBuilder2;
- String str2;
- if (paramBoolean)
- {
- StringBuilder localStringBuilder1 = new StringBuilder();
- char[] arrayOfChar1 = e.a(localRSAPublicKey.getModulus().toByteArray());
- String str1 = new String(arrayOfChar1);
- localStringBuilder2 = localStringBuilder1.append(str1).append("|");
- char[] arrayOfChar2 = e.a(localRSAPublicKey.getPublicExponent().toByteArray());
- str2 = new String(arrayOfChar2);
- }
- StringBuilder localStringBuilder4;
- BigInteger localBigInteger2;
- for (String str3 = str2; ; str3 = localBigInteger2)
- {
- return str3;
- StringBuilder localStringBuilder3 = new StringBuilder();
- BigInteger localBigInteger1 = localRSAPublicKey.getModulus();
- localStringBuilder4 = localStringBuilder3.append(localBigInteger1).append("|");
- localBigInteger2 = localRSAPublicKey.getPublicExponent();
- }
- }
- public PublicKey a(String paramString, boolean paramBoolean)
- {
- BigInteger[] arrayOfBigInteger = c(paramString, paramBoolean);
- try
- {
- KeyFactory localKeyFactory = KeyFactory.getInstance("RSA");
- BigInteger localBigInteger1 = arrayOfBigInteger[0];
- BigInteger localBigInteger2 = arrayOfBigInteger[1];
- RSAPublicKeySpec localRSAPublicKeySpec = new RSAPublicKeySpec(localBigInteger1, localBigInteger2);
- PublicKey localPublicKey = localKeyFactory.generatePublic(localRSAPublicKeySpec);
- return localPublicKey;
- }
- catch (Exception localException)
- {
- }
- throw new RuntimeException(localException);
- }
- public boolean a(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, PublicKey paramPublicKey)
- {
- b localb4;
- try
- {
- Signature localSignature = Signature.getInstance("SHA1withRSA", "BC");
- localSignature.initVerify(paramPublicKey);
- localSignature.update(paramArrayOfByte2);
- boolean bool = localSignature.verify(paramArrayOfByte1);
- return bool;
- }
- catch (SignatureException localSignatureException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb2 = b.c;
- throw new c(localb2, "900");
- }
- catch (NoSuchProviderException localNoSuchProviderException)
- {
- b localb3 = b.c;
- throw new c(localb3, "900");
- }
- catch (InvalidKeyException localInvalidKeyException)
- {
- localb4 = b.c;
- }
- throw new c(localb4, "900");
- }
- public byte[] a()
- {
- b localb2;
- try
- {
- KeyGenerator localKeyGenerator = KeyGenerator.getInstance("AES", "BC");
- localKeyGenerator.init(128);
- byte[] arrayOfByte = localKeyGenerator.generateKey().getEncoded();
- return arrayOfByte;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchProviderException localNoSuchProviderException)
- {
- localb2 = b.c;
- }
- throw new c(localb2, "900");
- }
- public byte[] a(int paramInt)
- {
- byte[] arrayOfByte = new byte[paramInt];
- k.nextBytes(arrayOfByte);
- return arrayOfByte;
- }
- public byte[] a(byte[] paramArrayOfByte, PrivateKey paramPrivateKey)
- {
- b localb6;
- try
- {
- Cipher localCipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
- localCipher.init(2, paramPrivateKey);
- byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte);
- return arrayOfByte;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchProviderException localNoSuchProviderException)
- {
- b localb2 = b.c;
- throw new c(localb2, "900");
- }
- catch (NoSuchPaddingException localNoSuchPaddingException)
- {
- b localb3 = b.c;
- throw new c(localb3, "900");
- }
- catch (IllegalBlockSizeException localIllegalBlockSizeException)
- {
- b localb4 = b.c;
- throw new c(localb4, "900");
- }
- catch (BadPaddingException localBadPaddingException)
- {
- b localb5 = b.c;
- throw new c(localb5, "900");
- }
- catch (InvalidKeyException localInvalidKeyException)
- {
- localb6 = b.c;
- }
- throw new c(localb6, "900");
- }
- public byte[] a(byte[] paramArrayOfByte, PublicKey paramPublicKey)
- {
- b localb6;
- try
- {
- Cipher localCipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
- localCipher.init(1, paramPublicKey);
- byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte);
- return arrayOfByte;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchProviderException localNoSuchProviderException)
- {
- b localb2 = b.c;
- throw new c(localb2, "900");
- }
- catch (NoSuchPaddingException localNoSuchPaddingException)
- {
- b localb3 = b.c;
- throw new c(localb3, "900");
- }
- catch (IllegalBlockSizeException localIllegalBlockSizeException)
- {
- b localb4 = b.c;
- throw new c(localb4, "900");
- }
- catch (BadPaddingException localBadPaddingException)
- {
- b localb5 = b.c;
- throw new c(localb5, "900");
- }
- catch (InvalidKeyException localInvalidKeyException)
- {
- localb6 = b.c;
- }
- throw new c(localb6, "900");
- }
- public byte[] a(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
- {
- SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
- b localb7;
- try
- {
- Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
- IvParameterSpec localIvParameterSpec = m;
- localCipher.init(2, localSecretKeySpec, localIvParameterSpec);
- byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte2);
- return arrayOfByte;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchProviderException localNoSuchProviderException)
- {
- b localb2 = b.c;
- throw new c(localb2, "900");
- }
- catch (NoSuchPaddingException localNoSuchPaddingException)
- {
- b localb3 = b.c;
- throw new c(localb3, "900");
- }
- catch (IllegalBlockSizeException localIllegalBlockSizeException)
- {
- b localb4 = b.c;
- throw new c(localb4, "900");
- }
- catch (BadPaddingException localBadPaddingException)
- {
- b localb5 = b.c;
- throw new c(localb5, "900");
- }
- catch (InvalidKeyException localInvalidKeyException)
- {
- b localb6 = b.c;
- throw new c(localb6, "900");
- }
- catch (InvalidAlgorithmParameterException localInvalidAlgorithmParameterException)
- {
- localb7 = b.c;
- }
- throw new c(localb7, "900");
- }
- public String b()
- {
- return UUID.randomUUID().toString();
- }
- public PrivateKey b(String paramString, boolean paramBoolean)
- {
- BigInteger[] arrayOfBigInteger = c(paramString, paramBoolean);
- try
- {
- KeyFactory localKeyFactory = KeyFactory.getInstance("RSA");
- BigInteger localBigInteger1 = arrayOfBigInteger[0];
- BigInteger localBigInteger2 = arrayOfBigInteger[1];
- RSAPrivateKeySpec localRSAPrivateKeySpec = new RSAPrivateKeySpec(localBigInteger1, localBigInteger2);
- PrivateKey localPrivateKey = localKeyFactory.generatePrivate(localRSAPrivateKeySpec);
- return localPrivateKey;
- }
- catch (Exception localException)
- {
- }
- throw new RuntimeException(localException);
- }
- public byte[] b(byte[] paramArrayOfByte, PrivateKey paramPrivateKey)
- {
- b localb4;
- try
- {
- Signature localSignature = Signature.getInstance("SHA1withRSA", "BC");
- localSignature.initSign(paramPrivateKey);
- localSignature.update(paramArrayOfByte);
- byte[] arrayOfByte = localSignature.sign();
- return arrayOfByte;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchProviderException localNoSuchProviderException)
- {
- b localb2 = b.c;
- throw new c(localb2, "900");
- }
- catch (InvalidKeyException localInvalidKeyException)
- {
- b localb3 = b.c;
- throw new c(localb3, "900");
- }
- catch (SignatureException localSignatureException)
- {
- localb4 = b.c;
- }
- throw new c(localb4, "900");
- }
- public byte[] b(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
- {
- b localb6;
- try
- {
- SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
- Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- IvParameterSpec localIvParameterSpec = m;
- localCipher.init(1, localSecretKeySpec, localIvParameterSpec);
- byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte2);
- return arrayOfByte;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchPaddingException localNoSuchPaddingException)
- {
- b localb2 = b.c;
- throw new c(localb2, "900");
- }
- catch (IllegalBlockSizeException localIllegalBlockSizeException)
- {
- b localb3 = b.c;
- throw new c(localb3, "900");
- }
- catch (BadPaddingException localBadPaddingException)
- {
- b localb4 = b.c;
- throw new c(localb4, "900");
- }
- catch (InvalidKeyException localInvalidKeyException)
- {
- b localb5 = b.c;
- throw new c(localb5, "900");
- }
- catch (InvalidAlgorithmParameterException localInvalidAlgorithmParameterException)
- {
- localb6 = b.c;
- }
- throw new c(localb6, "900");
- }
- public KeyPair c()
- {
- b localb2;
- try
- {
- KeyPairGenerator localKeyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
- localKeyPairGenerator.initialize(2048);
- KeyPair localKeyPair = localKeyPairGenerator.generateKeyPair();
- return localKeyPair;
- }
- catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
- {
- b localb1 = b.c;
- throw new c(localb1, "900");
- }
- catch (NoSuchProviderException localNoSuchProviderException)
- {
- localb2 = b.c;
- }
- throw new c(localb2, "900");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement