RSA签名 防数据篡改

clipboard.png
RSA签名加密
原理介绍
使用私钥将明文进行签名生成全密文串与明文一块儿传输,对方接受数据偶使用公钥对明文和密文进行验签。若是验签经过就说明:web

  • 数据没有被修改过
  • 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;spa

若是数据被修改:.net

@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;code

很简单,就一家话 “私钥签名,公钥验证”ip

对产品参数进行验签

@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),"验签失败");      
    }
}
相关文章
相关标签/搜索