我有一個使用第三方支付門戶的在線電子商務網站。支付門戶網站工作正常,直到第三方支付門戶網站要求每個人開始使用具有其他支付參數的散列碼。Java to ruby AES/ECB/PKCS5Padding加密
現在的問題是,第三方支付門戶網站只提供了一個用於實現散列鍵的頁面文檔。
這是所提供的文件: -
加密算法
爲了減輕參數回火/修改而傳送和數據的郵寄,商家可以加密使用由挪威電信POC提供的散列密鑰的請求。這個加密的請求與主要請求一起發送,然後在OPS端進行協調以檢測參數是否被更改。加密可以使用以下算法完成:
Create map of all the fields that are part of the request Map fields = new HashMap();
fields.put("amount", "10");
fields.put("storeId", "28");
fields.put("orderRefNum", "11001");
fields.put("expiryDate", "20150101 151515");
fields.put("postBackURL", " http://localhost:9081/local/status.php ");
Get the list of field name from the map created in the first step
List fieldNames = new ArrayList(fields.keySet());
Sort the map fields based on map key in alphabetical order
Collections.sort(fieldNames);
Create a string in following format: amount=10&expiryDate=20150101151515&orderRefNum=11001&postBackURL= http://localhost:9081/local/status.php&storeId=28
Use AES/ECB/PKCS5Padding algorithm to encrypt with the key and string produced in the previous step
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
encryptedValue = new String(Base64.encodeBase64(cipher.doFinal(value.getBytes())));
現在另一個問題是我沒有任何Java經驗。
我打電話給第三方支付平臺的求助熱線,他們只能幫我把鑰匙告訴我。
如果任何人都可以有所幫助,告訴我什麼是第5步的Ruby等價物,我將不勝感激。由於
剛試過所提供的代碼在網上Java編譯器: -
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class encryptData {
public static void main(String[] args) {
String data="amount=10&expiryDate=20150101 151515&orderRefNum=11001&postBackURL=http://localhost:9081/local/status.php&storeId=28";
String key="89OUITUPRL3I8H3G";
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
encryptedValue = new String(Base64.encodeBase64(cipher.doFinal(data.getBytes())));
}
}
這是錯誤: -
/tmp/java_Ramvov/encryptData.java:16:錯誤:無法找到符號
encryptedValue = new String(Base64.encodeBase64(cipher.doFinal(data.getBytes())));
^
符號:可變encryptedValue
位置:類encryptDa TA
/tmp/java_Ramvov/encryptData.java:16:錯誤:找不到符號
encryptedValue = new String(Base64.encodeBase64(cipher.doFinal(data.getBytes())));
^
符號:方法encodeBase64(字節[])
位置:類的Base64
2錯誤
任何幫助將不勝感激
我也有試圖重現此Java代碼紅寶石: -
data = "amount=10&expiryDate=20150101151515&orderRefNum=11001&postBackURL=http://localhost:9081/local/status.php&storeId=28"
cipher = OpenSSL::Cipher.new("AES-128-ECB")
cipher.encrypt()
cipher.key = "89OUITUPRL4I9H3G"
crypt = cipher.update(data) + cipher.final()
crypt_string = (Base64.encode64(crypt))
但是生成的加密是通過支付門戶
他們是否有示例輸出?所以你可以驗證你的執行的正確性 –
@Srgio Tulentsev沒有提供任何東西。他們現在剛給我的另一個信息是最後一步中的「值」變量是這個字符串「amount = 10&expiryDate = 20150101151515&orderRefNum = 11001&postBackURL = http:// localhost:9081/local/status.php&storeId = 28」 –
那麼,你怎麼能確定你正確實施了密碼?詢問他們的示例輸出。或者運行該java代碼。 –