st97
发表于 2016-6-7 12:49:30
给力 java自学网
ht9033@163.com
发表于 2016-6-8 11:21:44
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import java.util.Map;
/**
*
* @author 梁栋
* @version 1.0
* @since 1.0
*/
public class RSACoderTest {
private String publicKey;
private String privateKey;
@Before
public void setUp() throws Exception {
Map<String, Object> 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 test() throws Exception {
System.err.println("公钥加密——私钥解密");
String inputStr = "abc";
byte[] data = inputStr.getBytes();
byte[] encodedData = RSACoder.encryptByPublicKey(data, publicKey);
byte[] decodedData = RSACoder.decryptByPrivateKey(encodedData,
privateKey);
String outputStr = new String(decodedData);
System.err.println("加密前: " + inputStr + "\n\r" + "解密后: " + outputStr);
assertEquals(inputStr, outputStr);
}
@Test
public void testSign() throws Exception {
System.err.println("私钥加密——公钥解密");
String inputStr = "sign";
byte[] data = inputStr.getBytes();
byte[] encodedData = RSACoder.encryptByPrivateKey(data, privateKey);
byte[] decodedData = RSACoder
.decryptByPublicKey(encodedData, publicKey);
String outputStr = new String(decodedData);
System.err.println("加密前: " + inputStr + "\n\r" + "解密后: " + outputStr);
assertEquals(inputStr, outputStr);
System.err.println("私钥签名——公钥验证签名");
// 产生签名
String sign = RSACoder.sign(encodedData, privateKey);
System.err.println("签名:\r" + sign);
// 验证签名
boolean status = RSACoder.verify(encodedData, publicKey, sign);
System.err.println("状态:\r" + status);
assertTrue(status);
}
}
菜得要自杀
发表于 2016-6-11 03:25:33
挺好的java资源哦
649810411
发表于 2016-6-12 10:05:47
dsfadsfasdfasdfffffffffff
sailing
发表于 2016-6-12 11:09:18
感谢分享
感谢分享
JackChen
发表于 2016-6-12 15:48:34
感谢分享:handshake
qignshanz
发表于 2016-6-12 20:06:34
谢谢楼主分享!
moqiang02
发表于 2016-6-13 15:25:51
线看看再说
945117037
发表于 2016-6-13 15:51:29
好书。。。
1305462530
发表于 2016-6-16 10:28:10
可以下载 给力rabbitmq pdf
页:
1
2
3
4
5
[6]
7
8
9
10
11
12
13
14
15