function testGetCipherTextSpec() {
let cipherTextArray = new Uint8Array([48, 118, 2, 32, 45, 153, 88, 82, 104, 221, 226, 43, 174, 21, 122, 248, 5, 232, 105, 41, 92, 95, 102, 224, 216, 149, 85, 236, 110, 6, 64, 188, 149, 70, 70, 183, 2, 32, 107, 93, 198, 247, 119, 18, 40, 110, 90, 156, 193, 158, 205, 113, 170, 128, 146, 109, 75, 17, 181, 109, 110, 91, 149, 5, 110, 233, 209, 78, 229, 96, 4, 32, 87, 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201, 111, 143, 115, 169, 125, 128, 42, 157, 31, 114, 198, 109, 244, 4, 14, 100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]);
let cipherText : cryptoFramework.DataBlob = {data : cipherTextArray};
let spec : cryptoFramework.SM2CipherTextSpec = cryptoFramework.SM2CryptoUtil.getCipherTextSpec(cipherText, 'C1C3C2');
console.info('getCipherTextSpec success');
}
问题如下:
1.中spec 是什么格式?打印为[object Object] 用JSON.stringify(spec)打印报错
2.“开发者可指定SM2密文的参数”,中“密文的参数”指的是秘钥,还是加密后的参数?
spec 为命名空间cryptoFramework里面的一个抽象接口SM2CipherTextSpec,其定义了一种数据格式,并不是实体类。因此,并不能使用JSON来解析。
这里的“密文的参数”指的是密钥的参数,意思是可以指定密钥的参数,来生成符合国密标准的ASN.1格式密钥
可以分别打印其属性
密文的参数由四部分组成
xCoordinate:x分量,即C1\_X。bigint
yCoordinate:y分量,即C1\_Y。xCoordinate和yCoordinate可以转换成C1。bigint
cipherTextData:密文,即C2。Uint8Array
hashData:杂凑值,即C3。Uint8Array