登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

pcwanli的博客

nx

 
 
 

日志

 
 

如何使用16进制编码的RSA公钥进行RSA加密  

2016-05-30 04:10:10|  分类: 软件知识 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
java加密方法如下:

Java code
String modeHex = "D548C6267CC503F1E926776A97F8644CAA67167E8FA5D74FD1F4E0BCB3608BD1583E41B102B5B4617E53B90A0C67EA652F8D96B40CFDDA6BC1501432ADCE15E4B5B916568893C94FF3CAC5ED5942FC604BAD1B12DF7683B25C6702BD8CF1BE2F5A4FFC97C82E42FD91E49A6EFF379F5F022F36E5395D64FC9430EEFCAC55F0A5";
String exponentHex = "10001";

KeyFactory factory = KeyFactory.getInstance("RSA");

BigInteger n = new BigInteger(modeHex, 16);
BigInteger e = new BigInteger(exponentHex, 16);
RSAPublicKeySpec spec = new RSAPublicKeySpec(n, e);

RSAPublicKey pub = (RSAPublicKey) factory.generatePublic(spec);
Cipher enc = Cipher.getInstance("RSA");
enc.init(Cipher.ENCRYPT_MODE, pub);

byte[] encryptedContentKey = enc.doFinal(messageg.getBytes("GB2312"));

String result = new String(Hex.encodeHex(encryptedContentKey));java加密方法如下:

Java code
String modeHex = "D548C6267CC503F1E926776A97F8644CAA67167E8FA5D74FD1F4E0BCB3608BD1583E41B102B5B4617E53B90A0C67EA652F8D96B40CFDDA6BC1501432ADCE15E4B5B916568893C94FF3CAC5ED5942FC604BAD1B12DF7683B25C6702BD8CF1BE2F5A4FFC97C82E42FD91E49A6EFF379F5F022F36E5395D64FC9430EEFCAC55F0A5";
String exponentHex = "10001";

KeyFactory factory = KeyFactory.getInstance("RSA");

BigInteger n = new BigInteger(modeHex, 16);
BigInteger e = new BigInteger(exponentHex, 16);
RSAPublicKeySpec spec = new RSAPublicKeySpec(n, e);

RSAPublicKey pub = (RSAPublicKey) factory.generatePublic(spec);
Cipher enc = Cipher.getInstance("RSA");
enc.init(Cipher.ENCRYPT_MODE, pub);

byte[] encryptedContentKey = enc.doFinal(messageg.getBytes("GB2312"));

String result = new String(Hex.encodeHex(encryptedContentKey));java加密方法如下:java加密方法如下:

Java code
String modeHex = "D548C6267CC503F1E926776A97F8644CAA67167E8FA5D74FD1F4E0BCB3608BD1583E41B102B5B4617E53B90A0C67EA652F8D96B40CFDDA6BC1501432ADCE15E4B5B916568893C94FF3CAC5ED5942FC604BAD1B12DF7683B25C6702BD8CF1BE2F5A4FFC97C82E42FD91E49A6EFF379F5F022F36E5395D64FC9430EEFCAC55F0A5";
String exponentHex = "10001";

KeyFactory factory = KeyFactory.getInstance("RSA");

BigInteger n = new BigInteger(modeHex, 16);
BigInteger e = new BigInteger(exponentHex, 16);
RSAPublicKeySpec spec = new RSAPublicKeySpec(n, e);

RSAPublicKey pub = (RSAPublicKey) factory.generatePublic(spec);
Cipher enc = Cipher.getInstance("RSA");
enc.init(Cipher.ENCRYPT_MODE, pub);

byte[] encryptedContentKey = enc.doFinal(messageg.getBytes("GB2312"));

String result = new String(Hex.encodeHex(encryptedContentKey));
Java code
String modeHex = "D548C6267CC503F1E926776A97F8644CAA67167E8FA5D74FD1F4E0BCB3608BD1583E41B102B5B4617E53B90A0C67EA652F8D96B40CFDDA6BC1501432ADCE15E4B5B916568893C94FF3CAC5ED5942FC604BAD1B12DF7683B25C6702BD8CF1BE2F5A4FFC97C82E42FD91E49A6EFF379F5F022F36E5395D64FC9430EEFCAC55F0A5";
String exponentHex = "10001";

KeyFactory factory = KeyFactory.getInstance("RSA");

BigInteger n = new BigInteger(modeHex, 16);
BigInteger e = new BigInteger(exponentHex, 16);
RSAPublicKeySpec spec = new RSAPublicKeySpec(n, e);

RSAPublicKey pub = (RSAPublicKey) factory.generatePublic(spec);
Cipher enc = Cipher.getInstance("RSA");
enc.init(Cipher.ENCRYPT_MODE, pub);

byte[] encryptedContentKey = enc.doFinal(messageg.getBytes("GB2312"));

String result = new String(Hex.encodeHex(encryptedContentKey));java加密方法如下:

Java code
String modeHex = "D548C6267CC503F1E926776A97F8644CAA67167E8FA5D74FD1F4E0BCB3608BD1583E41B102B5B4617E53B90A0C67EA652F8D96B40CFDDA6BC1501432ADCE15E4B5B916568893C94FF3CAC5ED5942FC604BAD1B12DF7683B25C6702BD8CF1BE2F5A4FFC97C82E42FD91E49A6EFF379F5F022F36E5395D64FC9430EEFCAC55F0A5";
String exponentHex = "10001";

KeyFactory factory = KeyFactory.getInstance("RSA");

BigInteger n = new BigInteger(modeHex, 16);
BigInteger e = new BigInteger(exponentHex, 16);
RSAPublicKeySpec spec = new RSAPublicKeySpec(n, e);

RSAPublicKey pub = (RSAPublicKey) factory.generatePublic(spec);
Cipher enc = Cipher.getInstance("RSA");
enc.init(Cipher.ENCRYPT_MODE, pub);

byte[] encryptedContentKey = enc.doFinal(messageg.getBytes("GB2312"));

String result = new String(Hex.encodeHex(encryptedContentKey));java加密方法如下:

Java code
String modeHex = "D548C6267CC503F1E926776A97F8644CAA67167E8FA5D74FD1F4E0BCB3608BD1583E41B102B5B4617E53B90A0C67EA652F8D96B40CFDDA6BC1501432ADCE15E4B5B916568893C94FF3CAC5ED5942FC604BAD1B12DF7683B25C6702BD8CF1BE2F5A4FFC97C82E42FD91E49A6EFF379F5F022F36E5395D64FC9430EEFCAC55F0A5";
String exponentHex = "10001";

KeyFactory factory = KeyFactory.getInstance("RSA");

BigInteger n = new BigInteger(modeHex, 16);
BigInteger e = new BigInteger(exponentHex, 16);
RSAPublicKeySpec spec = new RSAPublicKeySpec(n, e);

RSAPublicKey pub = (RSAPublicKey) factory.generatePublic(spec);
Cipher enc = Cipher.getInstance("RSA");
enc.init(Cipher.ENCRYPT_MODE, pub);

byte[] encryptedContentKey = enc.doFinal(messageg.getBytes("GB2312"));

String result = new String(Hex.encodeHex(encryptedContentKey));
  评论这张
 
阅读(250)| 评论(0)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018