├── README.md ├── jasypt.png └── jasyptDecrypt ├── pom.xml └── src └── main └── java ├── Demo.java └── Main.java /README.md: -------------------------------------------------------------------------------- 1 | # spring-ENC | sprint encode (plan text) get enc password 2 | 3 | 参考链接: 4 | 5 | How to encrypt user passwords 6 | 7 | http://www.jasypt.org/howtoencryptuserpasswords.html 8 | 9 | 10 | ## 0x00简介 11 | 12 | 13 | Jasypt代表Java简化加密,它提供纯文本,数字和二进制文件的基本加密以保护机密数据,它是完全线程安全的,并且在多处理器中也提供高性能。 14 | 15 | Jasypt提供了更简单的加密和解密文本的方法,并且不需要任何深入的加密知识即可开始使用它,简单地,输入要加密的纯文本,Jasypt将完成其余的计算并为您这种加密是单向加密,它还提供了两种加密机制。 16 | 17 | 在实施双向加密时,除了提供纯文本之外,您还需要提供秘密文本,并且该秘密文本可用于解密加密的文本。 18 | 19 | 默认情况下,Jasypt使用PBEWithMD5AndDES加密算法,但它也提供选择其他更强加密选项的选项,例如PBEWithMD5AndTripleDES 20 | 21 | 22 | 23 | 24 | ## application.yml 25 | 26 | ``` 27 | spring: 28 | application: 29 | name: argus 30 | version: 2.0 31 | data: 32 | elasticsearch: #ElasticsearchProperties 33 | cluster-name: idss-es #默认即为elasticsearch 34 | datasource: 35 | url: jdbc:mysql://x.x.x.x:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true 36 | driver-class-name: com.mysql.jdbc.Driver 37 | username: ENC(vpIBjT3RT8mf6pBjiKJuqA==) root 38 | password: ENC(xxxxxxxxxxxxx==) 39 | 40 | # User, Password encryptor salt 41 | jasypt: 42 | encryptor: 43 | password: EbfYkitulv73I2p0mXI50JMXoaxZTKJ7 44 | ``` 45 | 46 | ## how to decode get plan text? 47 | 48 | 下面免费的Jasypt在线加密和解密工具提供了一种方法以及两种(简单)加密和解密选项,还提供了比较纯文本和Jasypt加密密码的选项。 49 | 50 | 51 | ``` 52 | username: ENC(vpIBjT3RT8mf6pBjiKJuqA==) 53 | 54 | # User, Password encryptor salt 55 | password: EbfYkitulv73I2p0mXI50JMXoaxZTKJ7 56 | 57 | ``` 58 | 59 | #### online decode for spring enc 60 | 61 | https://www.devglan.com/online-tools/jasypt-online-encryption-decryption 62 | 63 | 64 | ![](./jasypt.png) 65 | 66 | `username: ENC(vpIBjT3RT8mf6pBjiKJuqA==)` to `username: root` 67 | 68 | 69 | ### java 代码解密 70 | 71 | #### 使用方法: 72 | 73 | ``` 74 | $ java -jar jasyptDecrypt.jar 75 | _ _____ _ _____ _ 76 | | | | __ \| | | __ \ | | 77 | | | __ _ ___ _ _| |__) | |_| | | | ___ ___ _ __ _ _ _ __ | |_ 78 | _ | |/ _` / __| | | | ___/| __| | | |/ _ \/ __| '__| | | | '_ \| __| 79 | | |__| | (_| \__ \ |_| | | | |_| |__| | __/ (__| | | |_| | |_) | |_ 80 | \____/ \__,_|___/\__, |_| \__|_____/ \___|\___|_| \__, | .__/ \__| 81 | __/ | __/ | | 82 | |___/ |___/|_| 83 | 84 | Usage: 85 | [*] java -jar jasyptDecrypt.jar decode password EncodeText 86 | [*] java -jar jasyptDecrypt.jar encode password Text 87 | ``` 88 | 89 | #### 加密 90 | 91 | ``` 92 | $ java -jar jasyptDecrypt.jar encode EbfYkitulv73I2p0mXI50JMXoaxZTKJ7 root 93 | _ _____ _ _____ _ 94 | | | | __ \| | | __ \ | | 95 | | | __ _ ___ _ _| |__) | |_| | | | ___ ___ _ __ _ _ _ __ | |_ 96 | _ | |/ _` / __| | | | ___/| __| | | |/ _ \/ __| '__| | | | '_ \| __| 97 | | |__| | (_| \__ \ |_| | | | |_| |__| | __/ (__| | | |_| | |_) | |_ 98 | \____/ \__,_|___/\__, |_| \__|_____/ \___|\___|_| \__, | .__/ \__| 99 | __/ | __/ | | 100 | |___/ |___/|_| 101 | 102 | Usage: 103 | [*] java -jar jasyptDecrypt.jar decode password EncodeText 104 | [*] java -jar jasyptDecrypt.jar encode password Text 105 | 106 | [-] Encrypt: 107 | root >>> O9NmYDaJLpJQ6wl2/3TVpg== 108 | 109 | ``` 110 | 111 | #### 解密 112 | 113 | ``` 114 | $ java -jar jasyptDecrypt.jar decode EbfYkitulv73I2p0mXI50JMXoaxZTKJ7 vpIBjT3RT8mf6pBjiKJuqA== 115 | _ _____ _ _____ _ 116 | | | | __ \| | | __ \ | | 117 | | | __ _ ___ _ _| |__) | |_| | | | ___ ___ _ __ _ _ _ __ | |_ 118 | _ | |/ _` / __| | | | ___/| __| | | |/ _ \/ __| '__| | | | '_ \| __| 119 | | |__| | (_| \__ \ |_| | | | |_| |__| | __/ (__| | | |_| | |_) | |_ 120 | \____/ \__,_|___/\__, |_| \__|_____/ \___|\___|_| \__, | .__/ \__| 121 | __/ | __/ | | 122 | |___/ |___/|_| 123 | 124 | Usage: 125 | [*] java -jar jasyptDecrypt.jar decode password EncodeText 126 | [*] java -jar jasyptDecrypt.jar encode password Text 127 | 128 | [-] Decrypt: 129 | vpIBjT3RT8mf6pBjiKJuqA== >>> root 130 | 131 | ``` 132 | -------------------------------------------------------------------------------- /jasypt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jas502n/database-spring-ENC/20b63c11e227299621143351378718ed6e196844/jasypt.png -------------------------------------------------------------------------------- /jasyptDecrypt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | jasyptDecrypt 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 8 13 | 8 14 | 15 | 16 | 17 | 18 | 19 | org.jasypt 20 | jasypt 21 | 1.9.3 22 | 23 | 24 | 25 | 26 | 27 | ${project.artifactId} 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-assembly-plugin 32 | 33 | 34 | package 35 | 36 | single 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | Main 47 | 48 | 49 | 50 | 51 | jar-with-dependencies 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /jasyptDecrypt/src/main/java/Demo.java: -------------------------------------------------------------------------------- 1 | import org.jasypt.util.binary.AES256BinaryEncryptor; 2 | import org.jasypt.util.binary.BasicBinaryEncryptor; 3 | import org.jasypt.util.binary.StrongBinaryEncryptor; 4 | import org.jasypt.util.digest.Digester; 5 | import org.jasypt.util.numeric.*; 6 | import org.jasypt.util.password.BasicPasswordEncryptor; 7 | import org.jasypt.util.password.ConfigurablePasswordEncryptor; 8 | import org.jasypt.util.password.rfc2307.RFC2307MD5PasswordEncryptor; 9 | import org.jasypt.util.password.rfc2307.RFC2307SHAPasswordEncryptor; 10 | import org.jasypt.util.password.rfc2307.RFC2307SMD5PasswordEncryptor; 11 | import org.jasypt.util.password.rfc2307.RFC2307SSHAPasswordEncryptor; 12 | import org.jasypt.util.text.AES256TextEncryptor; 13 | import org.jasypt.util.text.BasicTextEncryptor; 14 | import org.jasypt.util.text.StrongTextEncryptor; 15 | import sun.misc.BASE64Encoder; 16 | 17 | import java.math.BigDecimal; 18 | import java.math.BigInteger; 19 | 20 | /** 21 | * @author: jas502n 22 | * Create Time: 2021/9/27 星期一 23 | * Project_Name: jasyptDecrypt 24 | * Package_Name: PACKAGE_NAME 25 | */ 26 | public class Demo { 27 | private final static String saltPassword = "passw0rd"; 28 | 29 | public static String AES256Encode(String saltPassword, String encodeText) { 30 | AES256TextEncryptor textEncryptor = new AES256TextEncryptor(); 31 | textEncryptor.setPassword(saltPassword); 32 | return textEncryptor.encrypt(encodeText); 33 | } 34 | 35 | public static String AES256Decode(String saltPassword, String text) { 36 | AES256TextEncryptor textEncryptor = new AES256TextEncryptor(); 37 | textEncryptor.setPassword(saltPassword); 38 | return textEncryptor.decrypt(text); 39 | 40 | } 41 | 42 | public static void main(String[] args) { 43 | try { 44 | String plainText = "123456"; 45 | 46 | // org.jasypt.util.binary 47 | AES256BinaryEncryptor aes256BinaryEncryptor = new AES256BinaryEncryptor(); 48 | aes256BinaryEncryptor.setPassword(saltPassword); 49 | System.out.println(new BASE64Encoder().encode(aes256BinaryEncryptor.encrypt(plainText.getBytes()))); 50 | 51 | BasicBinaryEncryptor basicBinaryEncryptor =new BasicBinaryEncryptor(); 52 | basicBinaryEncryptor.setPassword(saltPassword); 53 | System.out.println(new BASE64Encoder().encode(basicBinaryEncryptor.encrypt(plainText.getBytes()))); 54 | 55 | StrongBinaryEncryptor strongBinaryEncryptor =new StrongBinaryEncryptor(); 56 | strongBinaryEncryptor.setPassword(saltPassword); 57 | System.out.println(new BASE64Encoder().encode(strongBinaryEncryptor.encrypt(plainText.getBytes()))); 58 | 59 | 60 | // org.jasypt.util.numeric 61 | AES256DecimalNumberEncryptor aes256DecimalNumberEncryptor = new AES256DecimalNumberEncryptor(); 62 | aes256DecimalNumberEncryptor.setPassword(saltPassword); 63 | System.out.println(aes256DecimalNumberEncryptor.encrypt(new BigDecimal(plainText))); 64 | 65 | AES256IntegerNumberEncryptor aes256IntegerNumberEncryptor = new AES256IntegerNumberEncryptor(); 66 | aes256IntegerNumberEncryptor.setPassword(saltPassword); 67 | System.out.println(aes256IntegerNumberEncryptor.encrypt(new BigInteger(plainText))); 68 | 69 | BasicDecimalNumberEncryptor basicDecimalNumberEncryptor = new BasicDecimalNumberEncryptor(); 70 | basicDecimalNumberEncryptor.setPassword(saltPassword); 71 | System.out.println(basicDecimalNumberEncryptor.encrypt(new BigDecimal(plainText))); 72 | 73 | BasicIntegerNumberEncryptor basicIntegerNumberEncryptor = new BasicIntegerNumberEncryptor(); 74 | basicIntegerNumberEncryptor.setPassword(saltPassword); 75 | System.out.println(basicIntegerNumberEncryptor.encrypt(new BigInteger(plainText))); 76 | 77 | StrongDecimalNumberEncryptor strongDecimalNumberEncryptor = new StrongDecimalNumberEncryptor(); 78 | strongDecimalNumberEncryptor.setPassword(saltPassword); 79 | System.out.println(strongDecimalNumberEncryptor.encrypt(new BigDecimal(plainText))); 80 | 81 | StrongIntegerNumberEncryptor strongIntegerNumberEncryptor = new StrongIntegerNumberEncryptor(); 82 | strongIntegerNumberEncryptor.setPassword(saltPassword); 83 | System.out.println(strongIntegerNumberEncryptor.encrypt(new BigInteger(plainText))); 84 | 85 | // org.jasypt.util.digest 86 | Digester digester = new Digester(); 87 | System.out.println(new BASE64Encoder().encode(digester.digest(plainText.getBytes()))); 88 | 89 | // org.jasypt.util.password 90 | BasicPasswordEncryptor basicPasswordEncryptor = new BasicPasswordEncryptor(); 91 | System.out.println("BasicPasswordEncryptor: " + basicPasswordEncryptor.encryptPassword(plainText)); 92 | 93 | ConfigurablePasswordEncryptor configurablePasswordEncryptor = new ConfigurablePasswordEncryptor(); 94 | System.out.println("ConfigurablePasswordEncryptor: " + configurablePasswordEncryptor.encryptPassword(plainText)); 95 | 96 | 97 | // org.jasypt.util.password.rfc2307 98 | RFC2307MD5PasswordEncryptor rfc2307MD5PasswordEncryptor = new RFC2307MD5PasswordEncryptor(); 99 | System.out.println(rfc2307MD5PasswordEncryptor.encryptPassword(plainText)); 100 | 101 | RFC2307SHAPasswordEncryptor rfc2307SHAPasswordEncryptor = new RFC2307SHAPasswordEncryptor(); 102 | System.out.println(rfc2307SHAPasswordEncryptor.encryptPassword(plainText)); 103 | 104 | RFC2307SMD5PasswordEncryptor rfc2307SMD5PasswordEncryptor = new RFC2307SMD5PasswordEncryptor(); 105 | System.out.println(rfc2307SMD5PasswordEncryptor.encryptPassword(plainText)); 106 | 107 | RFC2307SSHAPasswordEncryptor rfc2307SSHAPasswordEncryptor = new RFC2307SSHAPasswordEncryptor(); 108 | System.out.println(rfc2307SSHAPasswordEncryptor.encryptPassword(plainText)); 109 | 110 | // org.jasypt.util.text 111 | AES256TextEncryptor aes256TextEncryptor = new AES256TextEncryptor(); 112 | aes256TextEncryptor.setPassword(saltPassword); 113 | System.out.println("AES256TextEncryptor: " + aes256TextEncryptor.encrypt(plainText)); 114 | 115 | BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor(); 116 | basicTextEncryptor.setPassword(saltPassword); 117 | System.out.println("BasicTextEncryptor: " + basicTextEncryptor.encrypt(plainText)); 118 | 119 | StrongTextEncryptor strongTextEncryptor = new StrongTextEncryptor(); 120 | strongTextEncryptor.setPassword(saltPassword); 121 | System.out.println("StrongTextEncryptor: " + strongTextEncryptor.encrypt(plainText)); 122 | 123 | 124 | System.out.println(AES256Encode(saltPassword, "123456")); 125 | System.out.println(AES256Decode(saltPassword, "DwxpUm488p5tMykVBJKSGxifp9oTZYrnaMBUqgJdwLPWTy2191XnQwrDaWLkxwdo")); 126 | 127 | } catch (Exception e) { 128 | e.printStackTrace(); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /jasyptDecrypt/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; 2 | 3 | /** 4 | * @author jas502n 5 | * Create Time: 2021/9/27 星期一 6 | * Project_Name: jasyptDecrypt 7 | * Package_Name: PACKAGE_NAME 8 | */ 9 | public class Main { 10 | 11 | 12 | public static String decryptor(String cryptoPassword, String encodeText) { 13 | StandardPBEStringEncryptor decryptor = new StandardPBEStringEncryptor(); 14 | decryptor.setPassword(cryptoPassword); 15 | return decryptor.decrypt(encodeText); 16 | } 17 | 18 | public static String encryptor(String cryptoPassword, String text) { 19 | StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); 20 | encryptor.setPassword(cryptoPassword); 21 | return encryptor.encrypt(text); 22 | } 23 | 24 | public static void main(String[] args) { 25 | 26 | try { 27 | String bannerInfo = " _ _____ _ _____ _ \n" + 28 | " | | | __ \\| | | __ \\ | | \n" + 29 | " | | __ _ ___ _ _| |__) | |_| | | | ___ ___ _ __ _ _ _ __ | |_ \n" + 30 | " _ | |/ _` / __| | | | ___/| __| | | |/ _ \\/ __| '__| | | | '_ \\| __|\n" + 31 | " | |__| | (_| \\__ \\ |_| | | | |_| |__| | __/ (__| | | |_| | |_) | |_ \n" + 32 | " \\____/ \\__,_|___/\\__, |_| \\__|_____/ \\___|\\___|_| \\__, | .__/ \\__|\n" + 33 | " __/ | __/ | | \n" + 34 | " |___/ |___/|_| \n" + 35 | "\n" + 36 | "Usage:\n" + 37 | "[*] java -jar jasyptDecrypt.jar decode password EncodeText\n" + 38 | "[*] java -jar jasyptDecrypt.jar encode password Text\n"; 39 | if (args.length == 0) { 40 | System.out.println(bannerInfo); 41 | System.exit(0); 42 | } 43 | if (args.length == 3) { 44 | String option = args[0]; 45 | if (option.equalsIgnoreCase("decode")) { 46 | String cryptoPassword = args[1]; 47 | String encodeText = args[2]; 48 | System.out.println(bannerInfo); 49 | System.out.println("[-] Decrypt: \n" + encodeText + " >>> " + decryptor(cryptoPassword, encodeText) + "\n"); 50 | } 51 | if (option.equalsIgnoreCase("encode")) { 52 | String cryptoPassword = args[1]; 53 | String text = args[2]; 54 | System.out.println(bannerInfo); 55 | System.out.println("[-] Encrypt: \n" + text + " >>> " + encryptor(cryptoPassword, text) + "\n"); 56 | } 57 | 58 | } 59 | 60 | 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | 65 | } 66 | } 67 | --------------------------------------------------------------------------------