java代码转c_java代码转c语言

这个Java类包含了一系列加密解密方法,如`MyEncryptAll`和`MyEncrypt`,它们使用了固定密钥进行异或操作。`ContentEncrypt`方法将字符串内容与时间戳结合加密,而`Decode`方法则用于解密。这些方法可能用于数据的安全传输和存储。
摘要由CSDN通过智能技术生成

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++也可以

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值