package com.jd.order.util.encryption;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
public class RSACoderTest {
private String publicKey;
private String privateKey;
@Before
public void setUp() throws Exception {
Map keyMap = RSACoder.initKey();
publicKey = RSACoder.getPublicKey(keyMap);
privateKey = RSACoder.getPrivateKey(keyMap);
System.err.println("公钥: \n\r" + publicKey);
System.err.println("私钥: \n\r" + privateKey);
}
@Test
public void testSignVerify() throws Exception {
String responseMsg = "abc";
System.err.println("私钥签名——公钥验证签名");
// 银行产生签名
String sign = RSACoder.sign(responseMsg.getBytes(), privateKey);
System.err.println("签名:\r" + sign);
// 客户验证签名
boolean status = RSACoder.verify(responseMsg.getBytes(), publicKey,
sign);
System.err.println("状态:\r" + status);
assertTrue(status);
}
}