You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							66 lines
						
					
					
						
							2.1 KiB
						
					
					
				
			
		
		
	
	
							66 lines
						
					
					
						
							2.1 KiB
						
					
					
				package com.ynxbd.common.helper.xbd;
 | 
						|
 | 
						|
import javax.crypto.Cipher;
 | 
						|
import javax.crypto.spec.IvParameterSpec;
 | 
						|
import javax.crypto.spec.SecretKeySpec;
 | 
						|
import java.nio.charset.StandardCharsets;
 | 
						|
import java.security.MessageDigest;
 | 
						|
import java.util.Base64;
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * @author 李进才
 | 
						|
 * @ClassName EncHelper
 | 
						|
 * @Description 在线病历打印请求的加密方法
 | 
						|
 * @date 2023/4/20 09:40
 | 
						|
 */
 | 
						|
public class EncHelper {
 | 
						|
    /**
 | 
						|
     * 密钥
 | 
						|
     */
 | 
						|
    private static final byte[] key = new byte[]{114, 120, 49, 55, 56, 103, 100, 109, 107, 50};
 | 
						|
    /**
 | 
						|
     * 向量长度
 | 
						|
     */
 | 
						|
    private static final byte[] ivB = new byte[]{88, 66, 68, 66, 108, 117, 101, 70, 108, 97, 103, 64, 54, 57, 33, 41};
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * AES加密
 | 
						|
     * @param encryptString 要被加密的字符串
 | 
						|
     * @return
 | 
						|
     * @throws Exception
 | 
						|
     */
 | 
						|
    public static String AES_Encrypt(String encryptString) throws Exception {
 | 
						|
        String keyValue = String.format("%-32s",  GetStr(key));
 | 
						|
        byte[] iv = (GetStr(ivB).substring(0, 16)).getBytes(StandardCharsets.UTF_8);
 | 
						|
        SecretKeySpec secretKeySpec = new SecretKeySpec(keyValue.getBytes(), "AES");
 | 
						|
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); //"算法/模式/补码方式"
 | 
						|
        IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
 | 
						|
        cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
 | 
						|
        byte[] inputData = encryptString.getBytes(StandardCharsets.UTF_8);
 | 
						|
        byte[] encrypted = cipher.doFinal(inputData);
 | 
						|
        return Base64.getEncoder().encodeToString(encrypted);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * 64位MD5加密
 | 
						|
     * @param context
 | 
						|
     * @return
 | 
						|
     * @throws Exception
 | 
						|
     */
 | 
						|
    public static String MD5Encrypt64(String context) throws Exception {
 | 
						|
        MessageDigest md5 = MessageDigest.getInstance("MD5");
 | 
						|
        byte[] digest = md5.digest(context.getBytes("utf-8"));
 | 
						|
        return Base64.getEncoder().encodeToString(digest);
 | 
						|
    }
 | 
						|
 | 
						|
    private static String GetStr(byte[] byteList) {
 | 
						|
        String valueStr = "";
 | 
						|
        for (byte b : byteList) {
 | 
						|
            valueStr += (char) b;
 | 
						|
        }
 | 
						|
        return valueStr;
 | 
						|
    }
 | 
						|
}
 | 
						|
 |