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
SignatureEcBcwith an extra byte for therecovery ID. Allows torecoverthepublic 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 byteBITCOIN_COMPRESSED_OFFSETAdditionalrecovery offsetused for BitCoin for compressed public key.static byteBITCOIN_RECOVERY_OFFSETrecovery offsetused 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.protectedSignatureEcBcWithRecoveryId(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 intgetHead()bytegetRecoveryId()bytegetRecoveryIndex()protected bytegetRecoveryOffset()booleanisCompressed()static SignatureEcBcWithRecoveryIdof(CryptoEllipticCurveBc curve, BigInteger r, BigInteger s, byte[] message, org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey publicKey, byte recoveryOffset)org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKeyrecoverPublicKey(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 offsetused 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 offsetused 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:
getHeadin classSignatureEcBc- Returns:
- number of bytes reserved at the beginning (header) of the
binarydata.
-
getRecoveryId
public byte getRecoveryId()
- Returns:
- the recovery ID containing the
recovery indexandcompressioninformation.
-
getRecoveryIndex
public byte getRecoveryIndex()
- Returns:
- the index to
recover the public keyfrom the signature. It is a value in the range from0to3.
-
getRecoveryOffset
protected byte getRecoveryOffset()
- Returns:
- the offset to add to the
recovery indexfor building therecovery ID.
-
isCompressed
public boolean isCompressed()
- Returns:
trueif public key was compressed,falseotherwise.
-
recoverPublicKey
public org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey recoverPublicKey(byte[] message)
- Specified by:
recoverPublicKeyin 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- theBCECPublicKeythat was used to sign the message.recoveryOffset- therecovery offset.- Returns:
- the signature.
-
-