IAIK ECC
version 2.18

iaik.security.ecc.util
Class SignatureFormater

java.lang.Object
  extended byiaik.security.ecc.util.SignatureFormater

public class SignatureFormater
extends java.lang.Object

A collection of methods used to format the ECDSA signature


Constructor Summary
SignatureFormater(byte[] signature)
          Parses a DER encoded signature of the format: ECDSA-Sig-Value ::= SEQUENCE { r INTEGER, s INTEGER }
 
Method Summary
static byte[] asn1toRawRS(byte[] sigBytes, int lengthRS)
          This method decodes an X.509 ECDSA signature and returns the raw r and s values in a byte array.
 java.math.BigInteger getR()
           
 java.math.BigInteger getS()
           
static byte[] getSignature(java.math.BigInteger r, java.math.BigInteger s)
           ECDSA-Sig-Value ::= SEQUENCE { r INTEGER, s INTEGER }
static byte[] rawRStoASN1(byte[] rs)
          This method encodes the raw r and s values of a ECDSA signature into an X.509 signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SignatureFormater

public SignatureFormater(byte[] signature)
                  throws java.lang.Exception
Parses a DER encoded signature of the format:
 ECDSA-Sig-Value ::= SEQUENCE {
   r INTEGER,
   s INTEGER
 }
 

Parameters:
signature - the byte array containing the signature
Method Detail

getSignature

public static byte[] getSignature(java.math.BigInteger r,
                                  java.math.BigInteger s)
 ECDSA-Sig-Value ::= SEQUENCE {
   r INTEGER,
   s INTEGER
 }
 

Returns:
the DER encoded ASN.1 structure

rawRStoASN1

public static byte[] rawRStoASN1(byte[] rs)
                          throws java.security.SignatureException
This method encodes the raw r and s values of a ECDSA signature into an X.509 signature. Some other libraries and standards use the raw r and s values as signature rather than the ASN.1 encoded values.

Parameters:
rs - The byte array containing the concatenation of r and s, most significant byte first (no signum bits).
Returns:
byte[] The X.509 encoded ECDSA signature value.
Throws:
java.security.SignatureException - If encoding the signature value fails.

asn1toRawRS

public static byte[] asn1toRawRS(byte[] sigBytes,
                                 int lengthRS)
                          throws java.security.SignatureException
This method decodes an X.509 ECDSA signature and returns the raw r and s values in a byte array.

Parameters:
sigBytes - The X.509 encoded ECDSA signature value.
lengthRS - The length of R and S in bytes, which have both the same length; e.g. 20 bytes. If this is 0, the byte length of r and s will be determined and the longer of both will be taken.
Returns:
The byte array containing the concatenation of r and s, most significant byte first (no signum bits).
Throws:
java.security.SignatureException - If decoding the signature value fails.

getR

public java.math.BigInteger getR()
Returns:
the r value of the signature

getS

public java.math.BigInteger getS()
Returns:
the s value of the signature

IAIK ECC
version 2.18

IAIK-ECC 2.18, (c) 2002 IAIK, (c) 2003 SIC