Module io.github.mmm.crypto.bc
Class SignatureEcBcWithRecoveryId
- java.lang.Object
-
- io.github.mmm.binary.BinaryType
-
- io.github.mmm.crypto.CryptoBinary
-
- io.github.mmm.crypto.asymmetric.sign.SignatureBinary
-
- io.github.mmm.crypto.asymmetric.sign.ec.bc.SignatureEcBc
-
- io.github.mmm.crypto.asymmetric.sign.ec.bc.SignatureEcBcWithRecoveryId
-
- All Implemented Interfaces:
Binary
,Streamable
,SignatureWithPublicKeyRecovery
public class SignatureEcBcWithRecoveryId extends SignatureEcBc implements SignatureWithPublicKeyRecovery
SignatureEcBc
with an extra byte for therecovery ID
. Allows torecover
thepublic key
. This enables to transfer only a compact hash of the public key to save capacity. E.g. BitCoin uses this to transmit a BitCoin Address instead of the actual public key.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static byte
BITCOIN_COMPRESSED_OFFSET
Additionalrecovery offset
used for BitCoin for compressed public key.static byte
BITCOIN_RECOVERY_OFFSET
recovery offset
used for BitCoin.-
Fields inherited from class io.github.mmm.binary.BinaryType
data
-
Fields inherited from interface io.github.mmm.binary.Binary
EMPTY_BYTE_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description SignatureEcBcWithRecoveryId(CryptoEllipticCurveBc curve, byte[] data, byte recoveryOffset)
The constructor.protected
SignatureEcBcWithRecoveryId(CryptoEllipticCurveBc curve, byte[] data, BigInteger r, BigInteger s, byte recoveryOffset)
The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
getHead()
byte
getRecoveryId()
byte
getRecoveryIndex()
protected byte
getRecoveryOffset()
boolean
isCompressed()
static SignatureEcBcWithRecoveryId
of(CryptoEllipticCurveBc curve, BigInteger r, BigInteger s, byte[] message, org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey publicKey, byte recoveryOffset)
org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey
recoverPublicKey(byte[] message)
-
Methods inherited from class io.github.mmm.crypto.asymmetric.sign.ec.bc.SignatureEcBc
calculateRecoveryIndex, createData, deserialize, getCurve, getR, getS, recoverPublicKey, recoverPublicKey
-
Methods inherited from class io.github.mmm.binary.BinaryType
asStream, equals, format, formatBase64, formatHex, getData, getData, getDataByte, getLength, getMaxLength, getMinLength, hashCode, isZeros, parseBase64, parseHex, save, toBytes, toBytes, toInt, toLong, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.binary.Binary
format, formatBase64, formatHex, getData, getData, getDataByte, getLength, isZeros
-
Methods inherited from interface io.github.mmm.binary.Streamable
asStream, save
-
-
-
-
Field Detail
-
BITCOIN_RECOVERY_OFFSET
public static final byte BITCOIN_RECOVERY_OFFSET
recovery offset
used for BitCoin. Nobody knows why this magic number was chosen.- See Also:
- Constant Field Values
-
BITCOIN_COMPRESSED_OFFSET
public static final byte BITCOIN_COMPRESSED_OFFSET
Additionalrecovery offset
used for BitCoin for compressed public key.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SignatureEcBcWithRecoveryId
protected SignatureEcBcWithRecoveryId(CryptoEllipticCurveBc curve, byte[] data, BigInteger r, BigInteger s, byte recoveryOffset)
The constructor.- Parameters:
curve
- theelliptic curve
.data
- thebinary data
.r
- - seeSignatureEcBc.getR()
.s
- - seeSignatureEcBc.getS()
.recoveryOffset
- therecovery offset
.
-
SignatureEcBcWithRecoveryId
public SignatureEcBcWithRecoveryId(CryptoEllipticCurveBc curve, byte[] data, byte recoveryOffset)
The constructor.- Parameters:
curve
- theelliptic curve
.data
- thebinary data
.recoveryOffset
- therecovery offset
.
-
-
Method Detail
-
getHead
protected int getHead()
- Overrides:
getHead
in classSignatureEcBc
- Returns:
- number of bytes reserved at the beginning (header) of the
binary
data.
-
getRecoveryId
public byte getRecoveryId()
- Returns:
- the recovery ID containing the
recovery index
andcompression
information.
-
getRecoveryIndex
public byte getRecoveryIndex()
- Returns:
- the index to
recover the public key
from the signature. It is a value in the range from0
to3
.
-
getRecoveryOffset
protected byte getRecoveryOffset()
- Returns:
- the offset to add to the
recovery index
for building therecovery ID
.
-
isCompressed
public boolean isCompressed()
- Returns:
true
if public key was compressed,false
otherwise.
-
recoverPublicKey
public org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey recoverPublicKey(byte[] message)
- Specified by:
recoverPublicKey
in interfaceSignatureWithPublicKeyRecovery
- Parameters:
message
- the payload (typically hash of message) that was signed when this signature was created.- Returns:
- the recovered public key.
-
of
public static SignatureEcBcWithRecoveryId of(CryptoEllipticCurveBc curve, BigInteger r, BigInteger s, byte[] message, org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey publicKey, byte recoveryOffset)
- Parameters:
curve
- theelliptic curve
.r
- the valuer
.s
- the values
.message
- the signed message (hash).publicKey
- theBCECPublicKey
that was used to sign the message.recoveryOffset
- therecovery offset
.- Returns:
- the signature.
-
-