Asn1 { public static BigInteger[] decodeToBigIntegerArray(byte[] signature) throws IOException { ASN1InputStream decoder = new ASN1InputStream(signature); DLSequence seq = (DLSequence) decoder.readObject(); ASN1Integer r = (ASN1Integer) seq.getObjectAt(0); ASN1Integer s = (ASN1Integer) seq.getObjectAt(1); decoder.close(); BigInteger[] ret = new BigInteger[2]; ret[0] = r.getPositiveValue(); ret[1] = s.getPositiveValue(); return ret; }  static byte[] getEncoded(BigInteger[] sigs); static BigInteger[] decodeToBigIntegerArray(byte[] signature); static byte[] toRawSignatureBytes(BigInteger[] rs); static BigInteger[] transformRawSignature(byte[] raw); static byte[] toUnsignedByteArray(BigInteger bi);  }
@Test public void rickSafeURLEncoding() throws IOException { String signatureB64 = "MEQCIAwtk4DStr2MqkrAlOVG+nyQxbS6tnBpVi7OcKCm8/5lAiBjVsv+b+7nI/306iNHrso/ruOaxY8IJy3jw2/zr17JEQ=="; String signatureB64Safe = "MEQCIAwtk4DStr2MqkrAlOVG-nyQxbS6tnBpVi7OcKCm8_5lAiBjVsv-b-7nI_306iNHrso_ruOaxY8IJy3jw2_zr17JEQ"; BigInteger[] bigIntegerArray = Asn1.decodeToBigIntegerArray(Base64.decodeBase64(signatureB64)); BigInteger[] bigIntegerArrayFromURLSafe = Asn1.decodeToBigIntegerArray(Base64.decodeBase64(signatureB64Safe)); assertTrue(bigIntegerArray[0].equals(bigIntegerArrayFromURLSafe[0])); assertTrue(bigIntegerArray[1].equals(bigIntegerArrayFromURLSafe[1])); }