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),"驗籤失敗");      
    }
}
相關文章
相關標籤/搜索