Guest User

Untitled

a guest
Mar 2nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. private String CLIENT_KEY = "&eF2W7@Eu~5wV+Bwm9*EA*FV";
  4. private String CLIENT = "STANDARD-BANK";
  5.  
  6.  
  7. TextView o, e, d;
  8. int ctLength;
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13. try {
  14. Log.d("INIT TO: ", CLIENT);
  15. Log.d("HMAC: ", "DOCUMENTSCANN - DEV key");
  16. byte[] documentScannKey = crypto("5SH6UAPW-6SZQU2D3-A4KWUU5A-BQANA7W5-QIOKVNXP-EMFGQO3P-SUKRI2KS-OZFL6MIX");
  17. Log.d("Encripted: ", documentScannKey.toString());
  18. Log.d("Decripted: ", decrypt(documentScannKey));
  19. Log.d("FINISH", "********************");
  20. Log.d("HMAC: ", "LIVENESS - DEV key");
  21. byte[] livenessKey = crypto("c1228826702b16d450775cad737e5189647aa774");
  22. Log.d("Encripted: ", livenessKey.toString());
  23. Log.d("Decripted: ", decrypt(livenessKey));
  24. Log.d("FINISH", "********************");
  25. Log.d("HMAC: ", "SUBMIT_DATA - DEV API key");
  26. byte[] apiKey = crypto("E9742373-BA5B-455D-90CB-8385991FC266");
  27. Log.d("Encripted: ", apiKey.toString());
  28. Log.d("Decripted: ", decrypt(apiKey));
  29. Log.d("FINISH", "********************");
  30. Log.d("HMAC: ", "SUBMIT_DATA - DEV SECRET key");
  31. byte[] secretKey = crypto("0B92DBFC-BC12-464B-B48C-EE201D18C3AA");
  32. Log.d("Encripted: ", secretKey.toString());
  33. Log.d("Decripted: ", decrypt(secretKey));
  34. Log.d("FINISH", "********************");
  35.  
  36. Log.d("HMAC: ", "SUBMIT_DATA - STA API key");
  37. byte[] apiKeySTA = crypto("E9742373-BA5B-455D-90CB-8385991FC266");
  38. Log.d("Encripted: ", apiKeySTA.toString());
  39. Log.d("Decripted: ", decrypt(apiKeySTA));
  40. Log.d("FINISH", "********************");
  41. Log.d("HMAC: ", "SUBMIT_DATA - STA SECRET key");
  42. byte[] secretKeySTA = crypto("0B92DBFC-BC12-464B-B48C-EE201D18C3AA");
  43. Log.d("Encripted: ", secretKeySTA.toString());
  44. Log.d("Decripted: ", decrypt(secretKeySTA));
  45. Log.d("FINISH", "********************");
  46.  
  47. Log.d("HMAC: ", "SUBMIT_DATA - PROD API key");
  48. byte[] apiKeyPROD = crypto("5A73D95C-C760-4606-9876-AA11958909CE");
  49. Log.d("Encripted: ", apiKeyPROD.toString());
  50. Log.d("Decripted: ", decrypt(apiKeyPROD));
  51. Log.d("FINISH", "********************");
  52. Log.d("HMAC: ", "SUBMIT_DATA - PROD SECRET key");
  53. byte[] secretKeyPROD = crypto("F4E1B92A-0B51-423A-A84F-140B0D3339DE");
  54. Log.d("Encripted: ", secretKeyPROD.toString());
  55. Log.d("Decripted: ", decrypt(secretKeyPROD));
  56. Log.d("FINISH", "********************");
  57. } catch (Exception e) {
  58. e.printStackTrace();
  59. }
  60.  
  61.  
  62. }
  63.  
  64. public byte[] crypto(String data) throws Exception {
  65. byte[] input = data.getBytes();
  66. // byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04,
  67. // 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
  68. // 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
  69. // 0x15, 0x16, 0x17 };
  70.  
  71. byte[] keyBytes = CLIENT_KEY.getBytes();
  72. SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
  73. Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
  74. //System.out.println(new String(input));
  75. //o.setText("Original: " + new String(input));
  76.  
  77. // encryption pass
  78. cipher.init(Cipher.ENCRYPT_MODE, key);
  79.  
  80. byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
  81. ctLength = cipher.update(input, 0, input.length, cipherText, 0);
  82. ctLength += cipher.doFinal(cipherText, ctLength);
  83. //System.out.println(new String(cipherText));
  84. //e.setText("Encrypted: " + new String(cipherText));
  85. System.out.println("ENCRYPT: " + ctLength);
  86.  
  87. return cipherText;
  88.  
  89.  
  90. }
  91.  
  92. public String decrypt(byte[] data) throws Exception {
  93. byte[] keyBytes = CLIENT_KEY.getBytes();
  94. SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
  95. Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
  96. cipher.init(Cipher.DECRYPT_MODE, key);
  97. byte[] plainText = new byte[cipher.getOutputSize(ctLength)];
  98. int ptLength = cipher.update(data, 0, ctLength, plainText, 0);
  99. ptLength += cipher.doFinal(plainText, ptLength);
  100. //System.out.println(new String(plainText));
  101. //d.setText("Decrypted: " + new String(plainText));
  102. System.out.println("DECRYPT " + ptLength);
  103. return new String(plainText);
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment