Skip to content

Commit a2bdff0

Browse files
committed
Small refactoring of SHA256 hashing
1 parent 2e3361f commit a2bdff0

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/main/java/com/danubetech/keyformats/crypto/impl/secp256k1_ES256K_PrivateKeySigner.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.danubetech.keyformats.crypto.impl;
22

33
import com.danubetech.keyformats.crypto.PrivateKeySigner;
4+
import com.danubetech.keyformats.crypto.provider.SHA256Provider;
45
import com.danubetech.keyformats.jose.JWSAlgorithm;
56
import org.bitcoinj.base.Sha256Hash;
67
import org.bitcoinj.base.internal.ByteUtils;
@@ -18,13 +19,19 @@ public secp256k1_ES256K_PrivateKeySigner(ECKey privateKey) {
1819
@Override
1920
public byte[] sign(byte[] content) throws GeneralSecurityException {
2021

21-
ECKey.ECDSASignature ecdsaSignature = this.getPrivateKey().sign(Sha256Hash.of(content));
22+
byte[] signatureBytes = new byte[64];
23+
24+
// sign
25+
26+
byte[] hash = SHA256Provider.get().sha256(content);
27+
ECKey.ECDSASignature ecdsaSignature = this.getPrivateKey().sign(Sha256Hash.wrap(hash));
2228
byte[] r = ByteUtils.bigIntegerToBytes(ecdsaSignature.r, 32);
2329
byte[] s = ByteUtils.bigIntegerToBytes(ecdsaSignature.s, 32);
24-
25-
byte[] signatureBytes = new byte[64];
2630
System.arraycopy(r, 0, signatureBytes, 0, r.length);
2731
System.arraycopy(s, 0, signatureBytes, 32, s.length);
32+
33+
// done
34+
2835
return signatureBytes;
2936
}
3037
}

0 commit comments

Comments
 (0)