|
|
|
@ -1,11 +1,23 @@
|
|
|
|
|
package au.com.royalpay.payment.manage.valid;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.analysis.beans.ato.CharacterUtils;
|
|
|
|
|
import au.com.royalpay.payment.manage.appclient.beans.RSvcMchBean;
|
|
|
|
|
import au.com.royalpay.payment.tools.codec.AESCrypt;
|
|
|
|
|
import au.com.royalpay.payment.tools.encryptalgorithm.SignUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.github.stuxuhai.jpinyin.PinyinException;
|
|
|
|
|
import com.github.stuxuhai.jpinyin.PinyinFormat;
|
|
|
|
|
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
|
|
|
|
import org.apache.commons.net.util.Base64;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import javax.crypto.BadPaddingException;
|
|
|
|
|
import javax.crypto.IllegalBlockSizeException;
|
|
|
|
|
import javax.crypto.NoSuchPaddingException;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.security.InvalidKeyException;
|
|
|
|
|
import java.security.Key;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.security.spec.InvalidKeySpecException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create by yixian at 2018-09-06 8:57
|
|
|
|
|
*/
|
|
|
|
@ -16,4 +28,38 @@ public class JPinYinTest {
|
|
|
|
|
|
|
|
|
|
System.out.println(CharacterUtils.convertFullWidthToHalfWidth(CharacterUtils.convertToPinYin(test)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRSA() throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, InvalidKeySpecException {
|
|
|
|
|
String rsa1_pub = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlxNzoulC++qq9a37bvNe5hyoWhlybZx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5Ey2N4DxSKPzHSqn+rdvQRAs2QaVPUcND63V7J5mpp97MzsqWzBiESG0jIoNys0IrpdrqHCkcMAtOukEZ9o+MQKBgQDJ9KB086XiS3gIYqgfutF2QuTTpm9sjuPr3Ij1Xq6xPo3Dxc1nCMNx8dnka0erwPZ1bypbQcvgjxjxuow1XsnbvY9dQpmg51eH1/oFoXHeuY4qel5LnODJ05RSPK25bYX29ezV4Fp+LX/5ZRQwJXojPvZhxB8i0RdMiNmPQzjbTwKBgQCRB0sL+w6dSndwKdUag5CjllO9fIxMhNYVfGpBye0dqJyeJ8m7h6oOkDgYUt1LJzBLXqilRhZNxJtm9ZsBipNbgFQSC+Gi51ZBgkLx/IA8DT4Kd9BOgZmZBuf+Bt03uKPJaVRGsyQB8e+aJntwy6zJFTkDYxtDH0rpQNYfEjRwEQKBgA+p3IQVnakWh2HHHRkQ6UwN1iegQgYecwkJGspFJLF0k5Q6lDrIkDgXNPolY/KrTbJAA/399W0eTCX7fQJqrqdPZX4rOzUinERZ+PdU1TscEy2yPfwJV9nvghJ6yFKYbwp/enYAJ6SfrMxQDafKUFXJfVyJ1IxjwTXba1xUL2W7AoGAc6PzW66wEVYqvzfWzWr22tR0JS87b0h9eqyqHib5XATKmpKpJztMZvgj50fCGWxWcwW+QoEoxFZqRXWiFiS1Tax+UY7QDRF55JOOfZyl1+eerAQAq99sVg0QAom/9V4jZNfX3JZvIYI15opGSdI2hsRrtW7CBvYxsGz7mT3cLoE=";
|
|
|
|
|
RSvcMchBean aaa = new RSvcMchBean();
|
|
|
|
|
aaa.setMerchantNumber("taylor");
|
|
|
|
|
aaa.setIndustryName("其他服务行业");
|
|
|
|
|
aaa.setIndustryCode("331");
|
|
|
|
|
aaa.setCredentialCode("7dlXrdvhyuN73NDpZsGYftdIMuZms1Qc");
|
|
|
|
|
aaa.setLogo("https://file.royalpay.com.au/open/2017/07/24/1500898932409_7uFGyWIpk4IRTQyT3INk2Nk3KHedOG.png");
|
|
|
|
|
aaa.setPayHost("http://192.168.1.6:9008/");
|
|
|
|
|
aaa.setPartnerCode("PINE");
|
|
|
|
|
aaa.setMerchantName("TEST");
|
|
|
|
|
String pubKeyEncCredentialCode = SignUtils.encData(aaa.getCredentialCode(), rsa1_pub);
|
|
|
|
|
String aesKeyStr = Base64.encodeBase64String(AESCrypt.randomKey().getEncoded());
|
|
|
|
|
Key key = AESCrypt.fromKeyString(Base64.decodeBase64(aesKeyStr));
|
|
|
|
|
String decCredentialCode = Base64.encodeBase64String(AESCrypt.encrypt(pubKeyEncCredentialCode.getBytes(StandardCharsets.UTF_8), key));
|
|
|
|
|
JSONObject result = (JSONObject) JSONObject.toJSON(aaa);
|
|
|
|
|
result.put("sign_type", "RSA2");
|
|
|
|
|
result.put("enc_data", decCredentialCode);
|
|
|
|
|
result.put("nonce_str", aesKeyStr);
|
|
|
|
|
result.put("timestamp", System.currentTimeMillis());
|
|
|
|
|
result.put("sign", SignUtils.buildSign(result.toJSONString(), rsa2_pri));
|
|
|
|
|
System.err.println(result);
|
|
|
|
|
String signa = result.getString("sign");
|
|
|
|
|
result.remove("sign");
|
|
|
|
|
SignUtils.checkStringSign(result.toJSONString(), signa, rsa2_pub);
|
|
|
|
|
String aesData = new String(AESCrypt.decrypt(Base64.decodeBase64(result.getString("enc_data")), key), StandardCharsets.UTF_8);
|
|
|
|
|
System.err.println(SignUtils.decData(aesData, rsa1_pri));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|