加密常用加解密工具类(md5、sha、des、aes、rsa)

md5解密  时间:2021-01-31  阅读:()

常用加解密工具类MD5、 S HA、 DES、 AES、 RS A

加解密工具类实现了常用的加解密类。包括单向加密MD5、 SHA对称加密 DES、AES非对称加密 RS A

完整代码见 https://git.os china.net/bayern.c om/S ecureUtils.git同时提供ant打包脚本。

Cipher cipher=Cipher.getInstanc e(ALGORIT HM);cipher.init(Cipher.ENCRYPT_MODE,md5Key);return c ipher.doFinal(data);

@Overridepublic byte[]decrypt(byte[]data) throws Exc eptionif(s ecretKey==null | | .equals(s ecretKey))throw new Exc eption( scretKey need to exists

SecretKey md5Key=getKey(secretKey);

Cipher cipher=Cipher.getInstanc e(ALGORIT HM);cipher.init(Cipher.DECRYPT_MODE,md5Key);return c ipher.doFinal(data);

PrivateKey rsaPrivateKey=getRS APrivateKey();

Cipher cipher=Cipher.getInstanc e(ALGORIT HM);cipher.init(Cipher.ENCRYPT_MODE, rsaPrivateKey);return c ipher.doFinal(data);

@Overridepublic byte[]decrypt(byte[]data) throws Exc eption

PrivateKey rsaPrivateKey=getRS APrivateKey();

Cipher cipher=Cipher.getInstanc e(ALGORIT HM);cipher.init(Cipher.DECRYPT_MODE, rsaPrivateKey);return c ipher.update(data);

*使用私钥对数据进行签名

*@param data

*@r eturn

*@throw s Exc eptionpublic String sign(byte[]data) throws Exc eption

PrivateKey rsaPrivateKey=getRS APrivateKey();

Signature signature=Signature.getInstanc e(SIGN_ALGORIT HM);s ignature.initS ign(rs aPrivateKey);s ignature.update(data);return enc oder(s ignature.s ign());

RSA非对称加密。公钥加密公钥解密公钥校验签名

@Overridepublic byte[] encrypt(byte[]data) throws Exc eptionif(public Key==null | | .equals(public Key))throw new Exc eption(publicKey is need exists

PublicKey rsaPublicKey=getRSAPublic Key(public Key);

Cipher cipher=Cipher.getInstanc e(ALGORIT HM);cipher.init(Cipher.ENCRYPT_MODE, rsaPublicKey);return c ipher.doFinal(data);

@Overridepublic byte[]decrypt(byte[]data) throws Exc eptionif(public Key==null | | .equals(public Key))throw new Exc eption(publicKey is need exists

PublicKey rsaPublicKey=getRSAPublic Key(public Key);

Cipher cipher=Cipher.getInstanc e(ALGORIT HM);cipher.init(Cipher.DECRYPT_MODE, rsaPublicKey);return c ipher.doFinal(data);

*使用公钥校验签名

*@param data

*@param sign

*@r eturn

*@throw s Exc eptionpublic boolean verifySign(byte[]data,String sign) throws Exceptionif(public Key==null | | .equals(public Key))throw new Exc eption(publicKey is need exists

PublicKey rsaPublicKey=getRSAPublic Key(public Key);

Signature signature=Signature.getInstanc e(SIGN_ALGORIT HM);s ignature.initVerify(rs aPublic Key);s ignature.update(data);return s ignature.verify(dec oder(s ign));

}

#推荐# cmivps:全场7折,香港不限流量VPS,支持Windows系统

cmivps香港VPS带来了3个新消息:(1)双向流量改为单向流量,相当于流量间接扩大一倍;(2)Hong Kong 2T、Hong Kong 3T、Hong Kong 无限流量,这三款VPS开始支持Windows系统,如果需要中文版Windows系统请下单付款完成之后发ticket要求官方更改即可;(3)全场7折年付、8折月付优惠,优惠码有效期一个月!官方网站:https://www.cmivp...

Hosteons:洛杉矶/纽约/达拉斯免费升级10Gbps端口,KVM年付21美元起

今年1月的时候Hosteons开始提供1Gbps端口KVM架构VPS,目前商家在LET发布消息,到本月30日之前,用户下单洛杉矶/纽约/达拉斯三个地区机房KVM主机可以从1Gbps免费升级到10Gbps端口,最低年付仅21美元起。Hosteons是一家成立于2018年的国外VPS主机商,主要提供VPS、Hybrid Dedicated Servers及独立服务器租用等,提供IPv4+IPv6,支持...

创梦云 香港沙田、长沙联通2核1G仅需29元一个月 挂机宝7元一个月

商家介绍:创梦云是来自国内的主机销售商,成立于2018年4月30日,创梦云前期主要从事免备案虚拟主机产品销售,现在将提供5元挂机宝、特惠挂机宝、香港云服务器、美国云服务器、低价挂机宝等产品销售。主打高性价比高稳定性挂机宝、香港云服务器、美国云服务器、香港虚拟主机、美国虚拟主机。官方网站:http://cmy0.vnetdns.com本次促销产品:地区CPU内存硬盘带宽价格购买地址香港特价云服务器1...

md5解密为你推荐
名侦探柯南644名侦探柯南新一出现的集数【600-现在的800多集】骁龙750g和765g哪个好骁龙765G,这里的g是什么意思?滚筒洗衣机和波轮洗衣机哪个好滚筒洗衣机和波轮洗衣机哪个好用?集成显卡和独立显卡哪个好独立显卡和集成显卡哪个更好些电视直播软件哪个好目前最好的电视直播软件是什么?浮动利率和固定利率哪个好房贷须知:固定还是浮动利率好宝来和朗逸哪个好宝来和朗逸哪个好手机杀毒软件哪个好手机用杀毒软件,用哪样的好51空间登录51空间,怎么添加啊?怎么登陆?群空间登录手机如何登录腾讯qq群空间
唯品秀 Dedicated BWH godaddy域名证书 e蜗 165邮箱 免费吧 国外代理服务器地址 vip购优惠 最好的qq空间 免费网页空间 web服务器搭建 服务器维护 华为k3 广东服务器托管 架设代理服务器 在线tracert iptables koss耳机 kosskeb79 更多