WeBASE-Front
WeBASE-Front copied to clipboard
国密链sm2Verify调用返回false
环境:
[chain] id=1 ; use SM crypto or not, should nerver be changed sm_crypto=true sm_crypto_channel=true
[compatibility] ; supported_version should nerver be changed supported_version=2.8.0
webase-front :1.5.3
合约代码:
`pragma solidity ^0.4.25;
contract Crypto { function sm3(bytes memory data) public view returns(bytes32){} function keccak256Hash(bytes memory data) public view returns(bytes32){} function sm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns(bool, address){} function curve25519VRFVerify(string memory input, string memory vrfPublicKey, string memory vrfProof) public view returns(bool,uint256){} }`
`pragma solidity ^0.4.25; import "./Crypto.sol";
contract MyTest1 {
Crypto crypto;
constructor() public {
crypto = Crypto(0x5006);
}
function getSm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns (bool flag , address result) {
(flag,result) = crypto.sm2Verify(message, publicKey, r, s);
return (flag,result);
}
}`
参数:
参数来自 front的合约管理-在线工具-签名工具 message: 0xa665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3 publicKey: 043346e54789d4a60dc6a4ba203239d75cef2f592013d598e98622f2458239770ecc50be28ebb9f8cf9f092c267f7816f7778caf2a548f78b0adb16f824229407d r: 0x0a5633785b90f1c12101f3b1ecbda807cd34f8acedf587c90250b184b29cc0aa s: 0xa1f2a0baaf74cec6603a82022fbd715140c25d35d276790337060727a7190678
**签名私钥:**bc0d801d8612337619a32552ee65a6b25f95c5aeb21c997db58d99dc09b624c0
结果:
[
"false",
"0x0000000000000000000000000000000000000000"
]
publicKey前缀中前两位04是wedpr自带的标志位,在展示时应该对这个publicKey做特殊处理
使用java-sdk的签名接口签名数据后,返回signDataStr。 验签的话,使用java-sdk的verify方法,代码见下。其中国密和ECDSA的输出signDataStr需要处理下: 国密:signDataStr 去掉00,去掉公钥.substring(2)字符串。 ECDSA: signDataStr 的前两位(00或04,,,)放后边。
public boolean verifyByType(String publicKey, byte[] message, byte[] signature,int encryptType) {
if (encryptType == CryptoType.SM_TYPE) {
byte[] messageHash = smCryptoSuite.hash(message);
return smCryptoSuite.verify(publicKey, messageHash, signature);
} else {
byte[] messageHash = ecdsaCryptoSuite.hash(message);
return ecdsaCryptoSuite.verify(publicKey, messageHash, signature);
}
}
个人使用的验签过程。供参考 参考官方验签过程:https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk/crypto.html