java ansi x9.9 mac,java-Delphi -ANSI X9.9 MAC 算法,该怎么解决

Java code/**

* 实现ECB加密,返回16位十六进制MAC码,如果出现异常返回null

*

* @param input

* 明文

* @param key

* 密钥十六进制(明文)

* @return 8位MAC码

*/

public String ecbEncrypt(String input, String key) {

byte[] mac = new byte[8];

byte[] temp = new byte[8];

int z = 0;

try {

byte[] bt = input.getBytes("iso-8859-1");

int len = bt.length;

int other = len % 8;

// 如果密文最后不足8个字节,则以0补足

if (other != 0) {

byte[] tt = bt;

bt = new byte[tt.length + (8 - other)];

System.arraycopy(tt, 0, bt, 0, len);

}

// 初始化mac数组,最明文的前8个字节,用来进行循环异或

for (int i = 0; i < 8; i++) {

mac[i] = bt[i];

}

// 循环异或

for (int i = 8; i <= bt.length; i++, z++) {

if (i != 8 && i % 8 == 0) {

for (int j = 0; j < 8; j++) {

mac[j] = (byte) (mac[j] ^ temp[j]);

}

z = 0;

temp = new byte[8];

}

if (i != bt.length) {

temp[z] = bt[i];

}

}

byte[] tmpResult = new byte[8];// 用来存放异或结果

tmpResult = [color=#FF6600]des(mac, String2Hex(key));[/color]

return Hex2String(tmpResult).toUpperCase();

} catch (Exception e) {

return null;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值