测试加密/解密执行结果: 1packagecom.xinyan.springcloud.tjt;23publicclassTestDecryptEncrypt {45publicstaticvoidmain(String[] args)throwsException {6String password = "taojietaoge";7//加密:8String encryptPassword =PasswordUtils.encryptPassword(password);9System.out.println("加密后:"+encryptPassword);10...
* @return*/publicstaticString getEncryptString(String str) {//基于BASE64编码,接收byte[]并转换成StringBASE64Encoder encoder =newBASE64Encoder();try{//按utf8编码byte[] bytes =str.getBytes(CHARSETNAME);//获取加密对象Cipher cipher =Cipher.getInstance(ALGORITHM);//初始化密码信息cipher.init(Cipher.E...
下面是一个使用jBCrypt库实现BCrypt加密的示例代码: importorg.mindrot.jbcrypt.BCrypt;publicclassBCryptUtil{publicstaticStringencrypt(Stringpassword){Stringsalt=BCrypt.gensalt();StringhashedPassword=BCrypt.hashpw(password,salt);returnhashedPassword;}publicstaticbooleanverify(Stringpassword,StringhashedPassword){return...
public class EncryptDemo { public static void main(String[] args) { StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setPassword("HelloWorld"); String enc = encryptor.encrypt("sevenlin"); System.out.println(enc); } } 1. 2. 3. 4. 5. 6. 7. 8. 使用&验...
out.println("jdk des encrypt:" + (rlt));//解密cipher.init(Cipher.DECRYPT_MODE, converyKeyCode); rlt = cipher.doFinal(rlt); System.out.println("jdk des decrypt:" + new String(rlt)); 1.2、BC方式 与JDK方式相比,只是在生成KEY的时候有所区别 //生成keySecurity.addProvider(new BouncyCastle...
public class HexDemoTest { @Test public void test01() { String data = "itcast" ; byte[] bytes = data.getBytes() ; //测试hex String encoded = Hex.encodeHexString(bytes) ; System.out.println(encoded); }} 5.2 base64编码 Base64编码要求把3个8位字节(3乘8=24)转化为4个6位的字节(...
public static String encrypt(String plaintext, String key) throws Exception { SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), ALGORITHM); Cipher cipher = Cipher.getInstance(TRANSFORMATION); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptedBytes =...
String plaintext = ConfigTools.decrypt(publicKey,ciphertext); System.out.println("解密后的字符串:" + plaintext); return plaintext; } 3. Modify the content information of the database configuration file a,modify password Replace the password with the password generated by the tool class DruidEn...
public static String encryptBASE64(byte[] key) throws Exception{ return (new BASE64Encoder()).encode(key); } } 2.MD5(Message Digest Algorithm)加密 MD5 是将任意长度的数据字符串转化成短小的固定长度的值的单向操作,任意两个字符串不应有相同的散列值。因此 MD5 经常用于校验字符串或者文件,因为如果文...
-e Encrypt the input data (default) -in file Input file to read from (default stdin) -iv IV IV to use, specified as a hexadecimal string -K key Key to use, specified as a hexadecimal string -md digest Digest to use to create a key from the passphrase ...