加密技术
来源:互联网 发布:云计算技术与应用课程 编辑:程序博客网 时间:2024/05/29 04:38
MD5:
public class RSAEncryption {// 创建密钥对生成器,指定加密和解密算法为RSApublic String[] Skey_RSA(int keylen) {// 输入密钥长度String[] output = new String[keylen];// 用来存储密钥的e n d p qtry {SecureRandom sr = new SecureRandom();KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");kpg.initialize(1024,sr);// 指定密钥的长度,初始化密钥对生成器KeyPair kp = kpg.generateKeyPair();// 生成密钥对RSAPublicKey puk = (RSAPublicKey) kp.getPublic();// 获得公钥RSAPrivateCrtKey prk = (RSAPrivateCrtKey) kp.getPrivate();BigInteger e = puk.getPublicExponent();BigInteger n = puk.getModulus();BigInteger d = prk.getPrivateExponent();BigInteger p = prk.getPrimeP();BigInteger q = prk.getPrimeQ();output[0] = e.toString();output[1] = n.toString();output[2] = d.toString();output[3] = p.toString();output[4] = q.toString();} catch (Exception e) {Logger.getLogger(RSA.class.getName()).log(Level.SEVERE, null, e);}return output;}// 加密 在RSA公钥中包含有两个整数信息:e和n。对于明文数字m,计算密文的公式是m的e次方再与n求模。public String Enc_RSA(String mingwen, String eStr, String nStr) {String miwen = new String();try {BigInteger e = new BigInteger(eStr);BigInteger n = new BigInteger(nStr);byte[] ptext = mingwen.getBytes("UTF8");BigInteger m = new BigInteger(ptext);BigInteger c = m.modPow(e, n);miwen = c.toString();} catch (Exception e) {// TODO: handle exceptionLogger.getLogger(RSA.class.getName()).log(Level.SEVERE, null, e);}return miwen;}// 解密public String Dec_RSA(String miwen, String dStr, String nStr) {StringBuffer mingwen = new StringBuffer();BigInteger d = new BigInteger(dStr);// 获取私钥的参数d,nBigInteger n = new BigInteger(nStr);BigInteger c = new BigInteger(miwen);BigInteger m = c.modPow(d, n);byte[] mt = m.toByteArray();for (int i = 0; i < mt.length; i++) {mingwen.append((char)mt[i]);}return mingwen.toString();}}
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- 加密技术
- java加密技术--RSA加密
- java加密技术-双向加密
- 【安全加密技术】 对称加密
- 关于URL加密技术
- 软件注册加密技术
- Oracle 按相同数据连续统计
- How to Perfectly Uninstall iTunes 10/9
- Oracle Consulting Prices(Oralce顾问在国外的价码)
- C# 编程规范(逐步总结)
- PDO报错:Cannot execute queries while other unbuffered queries are active.
- 加密技术
- C#基础知识梳理系列二:C#的演绎大师:类型
- ASP.NET 关于FORM认证
- 关于ubuntu中gurb有关文件配置
- Android Property
- 1040 凑表达式
- java 解析xml
- 对Java接口和抽象类的认识及分析
- 过滤select列表