加密算法
来源:互联网 发布:网达软件最新消息 编辑:程序博客网 时间:2024/05/03 06:56
public class text { static final byte[] bytes_a = new byte[]{66, 108, 111, 119, 102, 105, 115, 104}; static final byte[] bytes_key = new byte[]{104,101,108,108,111,50,48,49,55}; static final byte[] bytes_content = new byte[]{103,111,111,100,32,106,111,98,32,77,121,32,102,114,105,101,110,100}; public static void main(String[] args) { SecretKeySpec se_key = new SecretKeySpec(bytes_key,new String(bytes_a)); byte[] target = encrypt(se_key,bytes_content); System.out.println(new String(target)); byte[] bytes = decrypt(se_key,target); System.out.println(new String(bytes)); } public static byte[] encrypt(Key key, byte[] text){ try { Cipher cipher = Cipher.getInstance(new String(bytes_a)); cipher.init(Cipher.ENCRYPT_MODE,key); return cipher.doFinal(text); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } return null; } public static byte[] decrypt(Key key, byte[] text){ try { Cipher cipher = Cipher.getInstance(new String(bytes_a)); cipher.init(Cipher.DECRYPT_MODE,key); return cipher.doFinal(text); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } return null; }}
0 0
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法:
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 加密算法
- 幼教视频直播方案
- 【学习Spring框架】依赖注入和控制反转异同?
- 【Linux】Linux学习总结-ioctl
- tomcat的安装和配置
- 图片重叠,转换
- 加密算法
- angularJS依赖注入
- android工程构建错误记录
- Android如何生产导入arr包
- SSH框架搭建
- ORA-01653 无法在表空间扩展的解决办法 -- 增加表空间大小或给表空间增加数据文件
- 如何用BarTender创建特殊形状的条形码
- 耳蜗的构造
- 保持android设备唤醒状态