zoukankan      html  css  js  c++  java
  • 加密算法(使用版)

     1 public class text {
     2     static final byte[] bytes_a = new byte[]{66, 108, 111, 119, 102, 105, 115, 104};
     3     static final byte[] bytes_key = new byte[]{104,101,108,108,111,50,48,49,55};
     4     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};
     5     public static void main(String[] args) {
     6 
     7         
     8         SecretKeySpec se_key = new SecretKeySpec(bytes_key,new String(bytes_a));
     9        byte[] target =  encrypt(se_key,bytes_content);
    10         System.out.println(new String(target));
    11         byte[] bytes = decrypt(se_key,target);
    12         System.out.println(new String(bytes));
    13     }
    14 
    15     public static byte[] encrypt(Key key, byte[] text){
    16         try {
    17             Cipher cipher = Cipher.getInstance(new String(bytes_a));
    18             cipher.init(Cipher.ENCRYPT_MODE,key);
    19             return cipher.doFinal(text);
    20         } catch (NoSuchAlgorithmException e) {
    21             e.printStackTrace();
    22         } catch (NoSuchPaddingException e) {
    23             e.printStackTrace();
    24         } catch (InvalidKeyException e) {
    25             e.printStackTrace();
    26         } catch (BadPaddingException e) {
    27             e.printStackTrace();
    28         } catch (IllegalBlockSizeException e) {
    29             e.printStackTrace();
    30         }
    31         return null;
    32     }
    33     public static byte[] decrypt(Key key, byte[] text){
    34         try {
    35             Cipher cipher = Cipher.getInstance(new String(bytes_a));
    36             cipher.init(Cipher.DECRYPT_MODE,key);
    37             return cipher.doFinal(text);
    38         } catch (NoSuchAlgorithmException e) {
    39             e.printStackTrace();
    40         } catch (NoSuchPaddingException e) {
    41             e.printStackTrace();
    42         } catch (InvalidKeyException e) {
    43             e.printStackTrace();
    44         } catch (BadPaddingException e) {
    45             e.printStackTrace();
    46         } catch (IllegalBlockSizeException e) {
    47             e.printStackTrace();
    48         }
    49         return null;
    50     }
    51 }
    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;
    }
    }
  • 相关阅读:
    [java]java String.split()函数的用法分析
    [sql]java.sql.Types的具体对应值(jdbcType)
    [sql]join的5种方式:inner join、left(outer) join、right (outer) Join、full(outer) join、cross join
    [java]String和Date、Timestamp之间的转换
    [Eclipse]保存java文件时,自动删除不需要的包import
    [postgresql]ROWS is not applicable when function does not return a set问题解决
    [postgreSql]postgreSql数据库、模式、表、函数的删除与创建
    zbb20170816 oracle Oracle 查看表空间、数据文件的大小及使用情况sql语句
    zbb20170811 mysql远程连接报错: Host * is not allowed to connect to this MySQL server,解决方法
    zbb20170811 linux 给用户授予文件夹权限
  • 原文地址:https://www.cnblogs.com/Engi-xx/p/6276774.html
Copyright © 2011-2022 走看看