java ec_Java ECKey.setB方法代码示例

import javacard.security.ECKey; //导入方法依赖的package包/类

/**

* \brief Initialize an EC key with the curve parameters from buf.

*

* \param buf The buffer containing the EC curve parameters. It must be TLV with the following format:

* 81 - prime

* 82 - coefficient A

* 83 - coefficient B

* 84 - base point G

* 85 - order

* 87 - cofactor

*

* \param bOff The offset at where the first entry is located.

*

* \param bLen The remaining length of buf.

*

* \param key The EC key to initialize.

*

* \throw NotFoundException Parts of the data needed to fully initialize

* the key were missing.

*

* \throw InvalidArgumentsException The ASN.1 sequence was malformatted.

*/

private void initEcParams(byte[] buf, short bOff, short bLen, ECKey key) throws NotFoundException, InvalidArgumentsException {

short pos = bOff;

short len;

/* Search for the prime */

pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x81);

pos++;

len = UtilTLV.decodeLengthField(buf, pos);

pos += UtilTLV.getLengthFieldLength(len);

key.setFieldFP(buf, pos, len); // "p"

/* Search for coefficient A */

pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x82);

pos++;

len = UtilTLV.decodeLengthField(buf, pos);

pos += UtilTLV.getLengthFieldLength(len);

key.setA(buf, pos, len);

/* Search for coefficient B */

pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x83);

pos++;

len = UtilTLV.decodeLengthField(buf, pos);

pos += UtilTLV.getLengthFieldLength(len);

key.setB(buf, pos, len);

/* Search for base point G */

pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x84);

pos++;

len = UtilTLV.decodeLengthField(buf, pos);

pos += UtilTLV.getLengthFieldLength(len);

key.setG(buf, pos, len); // G(x,y)

/* Search for order */

pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x85);

pos++;

len = UtilTLV.decodeLengthField(buf, pos);

pos += UtilTLV.getLengthFieldLength(len);

key.setR(buf, pos, len); // Order of G - "q"

/* Search for cofactor */

pos = UtilTLV.findTag(buf, bOff, bLen, (byte) 0x87);

pos++;

len = UtilTLV.decodeLengthField(buf, pos);

pos += UtilTLV.getLengthFieldLength(len);

if(len == 2) {

key.setK(Util.getShort(buf, pos));

} else if(len == 1) {

key.setK(buf[pos]);

} else {

throw InvalidArgumentsException.getInstance();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值