RSA数字签名算法(1),三年老Android经验面经

public static String encryptByPriKey(String data, RSAPrivateKey priKey){

PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(priKey.getEncoded());

KeyFactory keyFactory;

PrivateKey key;

Signature sign;

byte[] result = null;

try {

keyFactory = KeyFactory.getInstance(“RSA”);

key = keyFactory.generatePrivate(keySpec);

sign = Signature.getInstance(“MD5withRSA”);

sign.initSign(key);

sign.update(data.getBytes());// 处理的内容

result = sign.sign();

} catch (Exception e) {

e.printStackTrace();

}

System.out.println(“rsa sign:”+Hex.encodeHexString(result));

System.out.println(“sign len:”+result.length+“,str hex:”+Hex.encodeHexString(result).length());

return Hex.encodeHexString(result);

}

/**

  • 公钥验证

  • @param data

  • @param pubKey

  • @param res

  • @return

  • @throws Exception

*/

public static boolean decryptByPubKey(String data, RSAPublicKey pubKey, String res) {

System.out.println(“res len:”+res.length());

X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKey.getEncoded());

KeyFactory keyFactory;

PublicKey key;

Signature sign;

boolean result = false;

try {

keyFactory = KeyFactory.getInstance(“RSA”);

key = keyFactory.generatePublic(x509KeySpec);

sign = Signature.getInstance(“MD5withRSA”);

sign.initVerify(key);

sign.update(data.getBytes());

result = sign.verify(Hex.decodeHex(res.toCharArray()));

} catch (Exception e) {

e.printStackTrace();

}

System.out.println(“rsa verify:”+result);

return result;

}

}

RSA.java

package com.pro.rsa;

import java.security.interfaces.RSAPrivateKey;

import java.security.interfaces.RSAPublicKey;

import java.util.HashMap;

public class RSA {

public final static String src = “hello world hello world hello world hello world hello world hello worldhello worldhello world hello world hello world hello world hello worldhello world hello world hello world hello world v hello world hello world hello world vhello world hello world”;

public final static String _src = “hello world hello world hello world hello world hello world hello worldhello worldhello world hello world hello world hello world hello worldhello world hello world hello world hello world v hello world hello world hello world vhello world hello world”;

public static void main(String[] args) {

// 登录rosp返回给客户端

HashMap<String, Object> map = RSAUtil.getKeys();

RSAPublicKey pubKey = (RSAPublicKey) map.get(“pubKey”);

RSAPrivateKey priKey = (RSAPrivateKey) map.get(“priKey”);

// 客户端get提交给服务器

String res= RSAUtil.encryptByPriKey(src, priKey);

// 服务端验证

RSAUtil.decryptByPubKey(_src, pubKey, res);

}

}

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

最后

95191)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-WUnXru5M-1710672295191)]

最后

想要了解更多关于大厂面试的同学可以**点击这里免费获取《面试文档》**除此之外,我也分享一些免费的优质资源,包括:Android学习PDF+架构视频+源码笔记高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 这几块的内容。分享给大家,非常适合近期有面试和想在技术道路上继续精进的朋友。快来获取学习资料吧~

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值