加密常用加解密工具类(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));

}

酷锐云香港(19元/月) ,美国1核2G 19元/月,日本独立物理机,

酷锐云是一家2019年开业的国人主机商家,商家为企业运营,主要销售主VPS服务器,提供挂机宝和云服务器,机房有美国CERA、中国香港安畅和电信,CERA为CN2 GIA线路,提供单机10G+天机盾防御,提供美国原生IP,支持媒体流解锁,商家的套餐价格非常美丽,CERA机房月付20元起,香港安畅机房10M带宽月付25元,有需要的朋友可以入手试试。酷锐云自开业以来一直有着良好的产品稳定性及服务态度,支...

美国云服务器 2核4G限量 24元/月 香港云服务器 2核4G限量 24元/月 妮妮云

妮妮云的来历妮妮云是 789 陈总 张总 三方共同投资建立的网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑妮妮云的市场定位妮妮云主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。妮妮云的售后保证妮妮云退款 通过于合作商的友好协商,云服务器提供2天内全额退款到网站余额,超过2天...

金山云:618年中促销,企业云服务器2核4G仅401.28元/年,827.64元/3年

金山云618年中促销活动正在进行中!金山云针对企业级新用户优惠力度比普通个人用户优惠力度要大,所以我们也是推荐企业新用户身份购买金山云企业级云服务器,尽量购买3年配置的,而不是限时秒杀活动中1年的机型。企业级用户购买金山云服务器推荐企业专区:云服务器N3 2核4G云服务器,1-5M带宽,827.64元/3年,性价比高,性能稳定!点击进入:金山云618年中促销活动目前,金山云基础型E1云服务器2核4...

md5解密为你推荐
金士顿内存卡真假如何辨别金士顿内存卡的真假?游戏内存修改器游戏修改器有哪些软银赛富李念为什么离婚?国内免备案服务器国内的服务器是都要备案是吗?有没有不需要备案的?p图软件哪个好用p图软件哪个好涡轮增压和自然吸气哪个好涡轮增压和自然吸气哪个更好,优缺点是什么?滚筒洗衣机和波轮洗衣机哪个好波轮洗衣机和滚桶洗衣机哪个好?哪个更实用?苹果x和xr哪个好苹果xr好还是苹果x好手机浏览器哪个好手机什么浏览器最好用雅思和托福哪个好考托福好考还是雅思好考哇?
深圳域名空间 购买域名和空间 漂亮qq空间 日本软银 256m内存 免费ftp空间 174.127.195.202 hnyd 国外在线代理 godaddy域名证书 域名转接 卡巴斯基试用版 1美金 免费dns解析 360云服务 海外空间 申请免费空间 lamp是什么意思 lamp什么意思 lamp的音标 更多