Skip to content

Commit

Permalink
修改makeSign。
Browse files Browse the repository at this point in the history
  • Loading branch information
hehaihao committed Jan 12, 2021
1 parent db61b98 commit 5ba22a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public boolean checkSig(byte[] publicKeyBin){
* @param sigStr
* @return
*/
public boolean checkApiSign(byte[] publicKeyBin,String message,String sigStr){
/*public boolean checkApiSign(byte[] publicKeyBin,String message,String sigStr){
if (Secp256k1.verify(PublicKey.parse(publicKeyBin), Hash.sha256(Hash.sha256(message.getBytes())), Signature.parse(OcMath.hexStringToByteArray(sigStr))))
return true;
else
return false;
}
}*/

public boolean checkSign(byte[] publicKeyBin,String message,String sigStr){
if (Secp256k1.verify(PublicKey.parse(publicKeyBin), Hash.sha256(Hash.sha256(OcMath.hexStringToByteArray(message))), Signature.parse(OcMath.hexStringToByteArray(sigStr))))
Expand All @@ -55,7 +55,7 @@ public boolean checkSign(byte[] publicKeyBin,String message,String sigStr){
* @return
*/
public String makeSign(byte[] privateKeyBin,String message){
return OcMath.toHexStringNoPrefix(Secp256k1.sign(privateKeyBin,Hash.sha256(Hash.sha256((message).getBytes()))).serialize());
return OcMath.toHexStringNoPrefix(Secp256k1.sign(privateKeyBin,Hash.sha256(Hash.sha256(OcMath.hexStringToByteArray(message)))).serialize());
}

public String getCommitData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static void main(String[] args) {


//服务端:提取json中公钥、整json内容以及header中的sign对其验签
System.out.println(mBaseActionBean.checkApiSign(mAccountBean.getPublicKeyBin(),jsonMsg,"30450221008fe7f0f7bb55da842522ba91565065eae37c0bf3b06b402b129c34b288d8084402202247716b7cb03545eb455ef36c7c4070db905250615a9a4b975d49f5dadc2441"));
// System.out.println(mBaseActionBean.checkApiSign(mAccountBean.getPublicKeyBin(),jsonMsg,"30450221008fe7f0f7bb55da842522ba91565065eae37c0bf3b06b402b129c34b288d8084402202247716b7cb03545eb455ef36c7c4070db905250615a9a4b975d49f5dadc2441"));
}
}

0 comments on commit 5ba22a4

Please sign in to comment.