栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将.Net RSA xml密钥移植到Java

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将.Net RSA xml密钥移植到Java

deprer
在您的示例中,这是进行base64解码吗?看起来您可能正在依赖
sun.misc.base64Deprer
它,并且依赖那些内部类通常不是一个好主意(例如,其他JVM不会拥有它)。您可以使用具有base64类进行解码的Apache
Commons Codec
。这是RSA加密和解密所需要的其余内容:

byte[] expBytes = base64.deprebase64(exponentElem.getText().trim()));byte[] modBytes = base64.deprebase64(modulusElem.getText().trim());byte[] dBytes = base64.deprebase64(dElem.getText().trim());BigInteger modules = new BigInteger(1, modBytes);BigInteger exponent = new BigInteger(1, expBytes);BigInteger d = new BigInteger(1, dBytes);KeyFactory factory = KeyFactory.getInstance("RSA");Cipher cipher = Cipher.getInstance("RSA");String input = "test";RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(modules, exponent);PublicKey pubKey = factory.generatePublic(pubSpec);cipher.init(Cipher.ENCRYPT_MODE, pubKey);byte[] encrypted = cipher.doFinal(input.getBytes("UTF-8"));System.out.println("encrypted: " + new String(encrypted));RSAPrivateKeySpec privSpec = new RSAPrivateKeySpec(modules, d);PrivateKey privKey = factory.generatePrivate(privSpec);cipher.init(Cipher.DECRYPT_MODE, privKey);byte[] decrypted = cipher.doFinal(encrypted);System.out.println("decrypted: " + new String(decrypted));


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/496575.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号