Hi, I got a the key: "HK8N99LQ" and the
value: "THBiUURtaHdCSDlFRWYva1VSRm5QUCtWN2NnditldVE2RnhEa zdLNHlwZEZZQnlxU0xDQ3Zlc1ZrV1RNNHgyamcyNXgvUFUxQk1 UQVpPLzJTVDZnR3ZIUTZLbjRoemo4aU9ORVdKZ21kdktjOEZqZ UM0bkwvd29hbWM3bXQ2cXcvbjZRaUdtZDU5ZWtUSlFMZm1DUHZ aL284OGdqd1JJTGNvQzczb1dISTNScFhSc3VDemRRVTM2bmNic lM4b2FuTWM5RUE2UnUvL1RoT0tSOGFScDltSHZaY2R2MHNQS2x COGZOOUkzazcvVmtCZ2FpTnNwZ3p4aGVBWkJtUWJzN1M2YnAyM DJvMXFUMHdCYk9MUG5vNUNOaEtrVTZCZ2RJWTh3dzNqMDR6VVk vMTNNUW0reGtrUT090" from http://api.cashcow.co.il/
to decrypt the code in c# the website provide this code:
public static string Decrypt(string app_token, string signed_request) { byte[] keyArray; //get the byte code of the string byte[] toEncryptArray = Convert.FromBase64String(signed_request); // app token string key = app_token; //if hashing was used get the hash code with regards to your key MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider(); keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key)); //release any resource held by the MD5CryptoServiceProvider hashmd5.Clear(); TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider(); //set the secret key for the tripleDES algorithm tdes.Key = keyArray; //mode of operation. there are other 4 modes. //We choose ECB(Electronic code Book) tdes.Mode = CipherMode.ECB; //padding mode(if any extra byte added) tdes.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = tdes.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock( toEncryptArray, 0, toEncryptArray.Length); //Release resources held by TripleDes Encryptor tdes.Clear(); //return the Clear decrypted TEXT return UTF8Encoding.UTF8.GetString(resultArray); }
but how I decrypt it in Java, I tried to use that code but I got error message:
public String Decrypt(String signed_request) { String decryptedString = null; try { // Generate the secret key specs. byte[] key = "HK8N99LQ".getBytes(); MessageDigest sha = MessageDigest.getInstance("MD5"); key = sha.digest(key); key = Arrays.copyOf(key, 16); // use only first 128 bit SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES"); // Instantiate the cipher Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); //DECRYPT_MODE cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] original = cipher.doFinal(signed_request.getBytes()); decryptedString = new String(original); } catch(Exception e) { String message = e.getMessage(); System.out.print(message); } return decryptedString; }
Error Message:
Input length must be multiple of 16 when decrypting with padded cipher.