public static String chr(int i) {
while (i < 0) {
i += 256;
}
i %= 256;
return Character.toString((char) i);
}
base64_decode
public static String base64Decode(String str) {
Base64.Decoder decoder = Base64.getDecoder();
byte[] bytes = decoder.decode(str);
StringBuffer sb1 = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
sb1.append(chr(bytes[i]));
}
return sb1.toString();
}
base64_encode
public static String base64Encode(String str) {
Base64.Encoder encoder = Base64.getEncoder();
byte[] bytes = encoder.encode(str.getBytes(StandardCharsets.ISO_8859_1));
return new String(bytes);
}
ord
public static int ord(String s) {
return s.length() > 0 ? (s.getBytes(StandardCharsets.UTF_8)[0] & 0xff) : 0;
}
public static int ord(char c) {
return c < 0x80 ? c : ord(Character.toString(c));
}