常用加解密工具类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));
}
酷锐云是一家2019年开业的国人主机商家,商家为企业运营,主要销售主VPS服务器,提供挂机宝和云服务器,机房有美国CERA、中国香港安畅和电信,CERA为CN2 GIA线路,提供单机10G+天机盾防御,提供美国原生IP,支持媒体流解锁,商家的套餐价格非常美丽,CERA机房月付20元起,香港安畅机房10M带宽月付25元,有需要的朋友可以入手试试。酷锐云自开业以来一直有着良好的产品稳定性及服务态度,支...
妮妮云的来历妮妮云是 789 陈总 张总 三方共同投资建立的网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑妮妮云的市场定位妮妮云主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。妮妮云的售后保证妮妮云退款 通过于合作商的友好协商,云服务器提供2天内全额退款到网站余额,超过2天...
金山云618年中促销活动正在进行中!金山云针对企业级新用户优惠力度比普通个人用户优惠力度要大,所以我们也是推荐企业新用户身份购买金山云企业级云服务器,尽量购买3年配置的,而不是限时秒杀活动中1年的机型。企业级用户购买金山云服务器推荐企业专区:云服务器N3 2核4G云服务器,1-5M带宽,827.64元/3年,性价比高,性能稳定!点击进入:金山云618年中促销活动目前,金山云基础型E1云服务器2核4...