code: public static byte[] toAsn1Der(byte[] signature, Ecdsa algorithm) {
          try {
              return Asn1DerSignatureEncoding.encode(signature, algorithm);
          } catch (IllegalArgumentException ex) {
              throw (IllegalArgumentException) new IllegalArgumentException(
                      ex.getMessage() + " " + Hex.encodeHexString(signature)).initCause(ex);
          }
      }
docs: Converts a raw ECDSA signature in the form R|S to an ASN.1 DER encoded signature.
  @param signature A raw ECDSA signature in the form R|S.
  @param algorithm The algorithm used to produce the given signature.
  @return The ASN.1 DER encoded signature of the given signature.