package Decode;

import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.binary.Base64;
public class Test {
public static String decode(String data, String key) throws UnsupportedEncodingException {
String temp = data;
byte[] bin = Base64.decodeBase64(temp.getBytes("utf-8"));
byte[] bout = new byte[bin.length];
byte[] bkey = key.getBytes();
for (int i = 0; i < bin.length; i++) {
bout[i] = (byte) (bin[i] - bkey[(i % bkey.length)]);
}
return new String(bout, 0, bout.length, "utf-8");
}
public static String encode(String
data, String key) throws
UnsupportedEncodingException {
byte[] bin = data.getBytes("utf-8");
byte[] bout = new byte[bin.length];
byte[] bkey = key.getBytes();
for (int i = 0; i < bin.length; i++) {
bout[i] = (byte) (bin[i] + bkey[(i % bkey.length)]);
}
return new String(Base64.encodeBase64(bout));
}
public static void
main(String[] args) throws
UnsupportedEncodingException {
System.out.println(encode("aaaaaaa", "abc"));
System.out.println(decode("YmRm", "abc"));
}
}

相关文章:

  • 2022-12-23
  • 2022-01-22
  • 2022-01-03
  • 2021-10-16
  • 2021-06-27
  • 2021-06-29
  • 2021-07-01
  • 2021-12-10
猜你喜欢
  • 2021-07-17
  • 2021-07-06
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
相关资源
相似解决方案