Package org.miaixz.bus.crypto.builtin
Class SaltMagic
java.lang.Object
org.miaixz.bus.crypto.builtin.SaltMagic
加盐值魔数
用于在OpenSSL生成的密文中,提取加盐值等相关信息
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int获取魔术值和随机盐的长度:16(128位)static final byte加盐值长度static final byte[]OpenSSL's magic initial bytes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]addMagic(byte[] data, byte[] salt) 为加密后的数据添加Magic头,生成的密文格式为:static byte[]getData(byte[] encryptedData) 获取去除头部盐的加密数据static byte[]getSalt(byte[] encryptedData) 获取8位salt随机数static byte[]getSalt(InputStream in) 获取流中的加盐值 不关闭流static byte[]getSaltedMagic(byte[] salt) 获取Magic头,生成的密文格式为:
-
Field Details
-
SALT_LEN
public static final byte SALT_LEN加盐值长度- See Also:
-
SALTED_MAGIC
public static final byte[] SALTED_MAGICOpenSSL's magic initial bytes. -
MAGIC_SALT_LENGTH
public static final int MAGIC_SALT_LENGTH获取魔术值和随机盐的长度:16(128位)
-
-
Constructor Details
-
SaltMagic
public SaltMagic()
-
-
Method Details
-
getData
public static byte[] getData(byte[] encryptedData) 获取去除头部盐的加密数据- Parameters:
encryptedData- 密文- Returns:
- 实际密文
-
getSalt
public static byte[] getSalt(InputStream in) throws org.miaixz.bus.core.lang.exception.InternalException 获取流中的加盐值 不关闭流- Parameters:
in- 流- Returns:
- salt
- Throws:
org.miaixz.bus.core.lang.exception.InternalException- IO异常
-
getSalt
public static byte[] getSalt(byte[] encryptedData) 获取8位salt随机数- Parameters:
encryptedData- 密文- Returns:
- salt随机数
-
addMagic
public static byte[] addMagic(byte[] data, byte[] salt) 为加密后的数据添加Magic头,生成的密文格式为:Salted__[salt][data]- Parameters:
data- 数据salt- 加盐值,必须8位,null表示返回原文- Returns:
- 密文
-
getSaltedMagic
public static byte[] getSaltedMagic(byte[] salt) 获取Magic头,生成的密文格式为:Salted__[salt]- Parameters:
salt- 加盐值,必须8位,不能为null- Returns:
- Magic头
-