Java实现国密Z值填充

3 篇文章 0 订阅
2 篇文章 0 订阅
private String zPadding(String pubkeyHex,String inDataHex){
		String smX="";
		String smY="";
		String userID="";
		String hexdata = inDataHex;
		String publicKeyHex = pubkeyHex;
		if(publicKeyHex!=null&& !"".equals(publicKeyHex)){
			smX=publicKeyHex.substring(0,64);
			smY=publicKeyHex.substring(64,publicKeyHex.length());
		}
		userID="31323334353637383132333435363738";
		byte[]zpading=SM2.Instance().sm2GetZSM( FileManager.hexToBytes(userID),smX, smY);
		hexdata=FileManager.bytesToHex(zpading)+hexdata;
		
		return hexdata;
	}

初始向量设置是31323334353637383132333435363738  对应是12345678, 公钥截取头32字节作为公钥X,截取后32字节作为公钥Y ,使用公钥X和Y做SM3运算

public byte[] sm2GetZSM(byte[] userId,String smX,String smY)
	{
		SM3Digest sm3 = new SM3Digest();
		
		int len = userId.length * 8;
		sm3.update((byte) (len >> 8 & 0xFF));
		sm3.update((byte) (len & 0xFF));
		sm3.update(userId, 0, userId.length);
		
		byte[] p = Util.byteConvert32Bytes(ecc_a);
		sm3.update(p, 0, p.length);
		
		p = Util.byteConvert32Bytes(ecc_b);
		sm3.update(p, 0, p.length);
		
		p = Util.byteConvert32Bytes(ecc_gx);
		sm3.update(p, 0, p.length);
		
		p = Util.byteConvert32Bytes(ecc_gy);
		sm3.update(p, 0, p.length);
		
		//p = Util.byteConvert32Bytes(userKey.getX().toBigInteger());
		p = Util.hexStringToBytes(smX);
		sm3.update(p, 0, p.length);
		
	//	p = Util.byteConvert32Bytes(userKey.getY().toBigInteger());
		p =  Util.hexStringToBytes(smY);
		sm3.update(p, 0, p.length);
		
		byte[] md = new byte[sm3.getDigestSize()];
		sm3.doFinal(md, 0);
		return md;
	}

可以下载附件获取

https://download.csdn.net/download/qgy92320/11878279

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NeoChing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值