RSA签名加密
原理介绍
使用私钥将明文进行签名生成全密文串与明文一起传输,对方接受数据偶使用公钥对明文和密文进行验签。如果验签通过就说明:
- 数据没有被修改过
- Sign一定是经过持有私钥的人签名的,起到防抵赖的作用。
谁签名? 套壳公司
谁验签? 有牌照的金融公司
为什么是非对称?
哪里有相关介绍?
使用方法
依赖:
<!--============================RSA===========================-->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.8</version>
</dependency>
工具类;
在线生成秘钥对;
测试方法:
@Test
public void singTest(){
String test="Hello World";
String sing= RSAUtil.sign(test,privateKey);
System.out.println(sing);
Boolean result=RSAUtil.verify(test,sing,publicKey);
System.out.println(result);
}
返回true;
如果数据被修改:
@Test
public void singTest(){
String test="Hello World";
String sign= RSAUtil.sign(test,privateKey);
System.out.println(sign);
test+="a";
Boolean result=RSAUtil.verify(test,sign,publicKey);
System.out.println(result);
}
返回false;
很简单,就一家话 “私钥签名,公钥验证”
对产品参数进行验签
@Component
@Aspect
public class SignAop {
@Autowired
private KeyService keyService;
@Before(value = "execution(* com.momo.seller.controller.*.*(..)) && args(authId,sign,param,..)")
public void verify(String authId, String sign, OrderParam param){
String publicKey = keyService.getPublicKey(authId);
Assert.isTrue(RSAUtil.verify(param.toText(),sign,publicKey),"验签失败");
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。