package com.sanyi.metaverse.util;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.util.Base64;
public class EncryptionUtil {
private static final String ENCRYPTION_NAME = "Blowfish";
// 密签
private static final String ENCRYPTION_KEY = "kgKAWr2Y0UQtqyyenObo1f4OumUUs0mnCQG+TyMQglI=";
private static Key createKey() {
byte[] keyBytes = ENCRYPTION_KEY.getBytes(StandardCharsets.UTF_8);
Key key = new SecretKeySpec(keyBytes, ENCRYPTION_NAME);
return key;
}
public static String encrypt(String plainText) throws Exception {
Key key = createKey();
Cipher encryptCipher = Cipher.getInstance(ENCRYPTION_NAME);
encryptCipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encrypted = encryptCipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8))
JAVA 生成秘钥
最新推荐文章于 2024-05-16 10:23:10 发布