Try www.bouncycastle.org. There are also some "hidden" classes shipped
with Sun's Java, but they are not documented and may therefore change
with java versions.
JK
> I finally found that SHA1withDSA signatures generated
> by the Java security API are encoded using ASN1 rules,
[quoted text clipped - 10 lines]
>
> Arch.
> I finally found that SHA1withDSA signatures generated
> by the Java security API are encoded using ASN1 rules,
[quoted text clipped - 10 lines]
>
> Arch.
You could use bouncy castle's ASN.1 parser. It's pretty good.
If you know what you'r doing, you can parse ASN.1 DER like
maybe something like this:
/** Returns an array of [b|s] */
static byte[] convertToRfc2437(byte[] signatureValue)
{
// ----------------------------------------------------------------
// | 0x30 len | 0x02 len(r) | ... r ... | 0x02 len(s) | ... s ... |
// ----------------------------------------------------------------
int start = 4;
int len = signatureValue[start - 1];
byte[] data = new byte[len];
System.arraycopy(signatureValue, start, data, 0, len);
byte[] r = fit(data, 20);
start += len + 2;
len = signatureValue[start - 1];
data = new byte[len];
System.arraycopy(signatureValue, start, data, 0, len);
byte[] s = fit(data, 20);
byte[] b = new byte[40];
System.arraycopy(r, 0, b, 0, 20);
System.arraycopy(s, 0, b, 20, 20);
return b;
}
/**
* Fit (stretch or shrink) b into an array without losing precision,
* as required by I2OSP.
*/
private static byte[] fit(byte[] b, int length)
{
int len = b.length;
int offset = (b[0] == 0) ? 1 : 0;
len -= offset;
if (len > length){
// DSA value too large to fit
// into 'length' bytes -- this should probably
// be handled . . .
len = length;
}
byte[] bytes = new byte[length];
System.arraycopy(b, offset, bytes, length - len, len);
return bytes;
}