public class Test {
public static void main(String[] args) throws UnsupportedEncodingException {
String text = "123";
final Base64.Decoder decoder = Base64.getDecoder();
final Base64.Encoder encoder = Base64.getEncoder();
byte[] textByte = text.getBytes(StandardCharsets.UTF_8);
//加密
for (int i = 0; i < textByte.length; i++){
textByte[i] = (byte)(textByte[i] ^ 0xFF);
}
//编码
final String encodedText = encoder.encodeToString(textByte);
//打印密文
System.out.println(encodedText);
//解码
byte[] secreteByte = decoder.decode(encodedText);
//解密
for (int i = 0; i < secreteByte.length; i++){
secreteByte[i] = (byte)(secreteByte[i] ^ 0xFF);
}
//明文密码
String key = new String(secreteByte, StandardCharsets.UTF_8);
System.out.println(key);
}
}
最简单的加解密方法:Base64+按位异或
最新推荐文章于 2022-04-10 16:04:23 发布