publicclassEncryption{publicstaticbyte[]Key=newbyte[]{0x70,0x30,0x64,0x31};publicstaticbyte[]MyEncryptAll(byte[]Message,byte[]TimeStamp){byte[]key=MyEncrypt(TimeStamp);re...
public class Encryption {
public static byte[] Key = new byte[] { 0x70, 0x30,
0x64, 0x31 };
public static byte[] MyEncryptAll(byte[] Message, byte[] TimeStamp) {
byte[] key = MyEncrypt(TimeStamp);
return MyEncrypt(Message, key);
}
public static byte[] MyEncrypt(byte[] Message, byte[] Key) {
byte[] bsResult = new byte[Message.length];
for (int i = 0, j = 0; i < Message.length; i++, j++) {
bsResult[i] = (byte) (Message[i] ^ Key[j % Key.length]);
}
return bsResult;
}
public static byte[] MyEncrypt(byte[] Message) {
byte[] bsResult = new byte[Message.length];
for (int i = 0, j = 0; i < Message.length; i++, j++) {
bsResult[i] = (byte) (Message[i] ^ Key[j % Key.length]);
}
return bsResult;
}
public static String ContentEncrypt(String content, String timestamp) {
byte[] key = MyEncrypt(ByteUtil.Hex2Bytes(timestamp));
byte[] Cryptogram = null;
try {
Cryptogram = MyEncrypt(content.getBytes("UTF-8"), key);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return Base64.encodeToString(Cryptogram, Base64.DEFAULT);
}
public static String Decode(byte[] content, String timestamp) {
byte[] key = MyEncrypt(ByteUtil.Hex2Bytes(timestamp));
byte[] Cryptogram = null;
Cryptogram = MyEncrypt(content, key);
return new String(Cryptogram);
}
}
转成obj-c或c++也可以
展开
这个Java类包含了一系列加密解密方法,如`MyEncryptAll`和`MyEncrypt`,它们使用了固定密钥进行异或操作。`ContentEncrypt`方法将字符串内容与时间戳结合加密,而`Decode`方法则用于解密。这些方法可能用于数据的安全传输和存储。
207

被折叠的 条评论
为什么被折叠?



