code: public static byte[] toAsn1Der(byte[] signature, String algorithm) throws NoSuchAlgorithmException {
          Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithm);
  
          // verify the given algoritm could be resolved
          if (baseAlgorithm == null) {
              throw new NoSuchAlgorithmException(algorithm);
          }
  
          // verify the given algoritm is an Ecdsa signature algorithm
          if (!(baseAlgorithm instanceof Ecdsa)) {
              throw new IllegalArgumentException("Invalid algorithm; must be an instance of ECDSA.");
          }
  
          return SignatureEncoding.toAsn1Der(signature, (Ecdsa) baseAlgorithm);
      }
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.