code: public void derEncode (OutputStream out) throws IOException {
          DerOutputStream bytes = new DerOutputStream();
          DerOutputStream tmp = new DerOutputStream();
  
          bytes.putOID(algid);
          // Setup params from algParams since no DER encoding is given
          if (constructedFromDer == false) {
              if (algParams != null) {
                  params = new DerValue(algParams.getEncoded());
              } else {
                  params = null;
              }
          }
          if (params == null) {
              // Changes backed out for compatibility with Solaris
  
              // Several AlgorithmId should omit the whole parameter part when
              // it's NULL. They are ---
              // rfc3370 2.1: Implementations SHOULD generate SHA-1
              // AlgorithmIdentifiers with absent parameters.
              // rfc3447 C1: When id-sha1, id-sha256, id-sha384 and id-sha512
              // are used in an AlgorithmIdentifier the parameters (which are
              // optional) SHOULD be omitted.
              // rfc3279 2.3.2: The id-dsa algorithm syntax includes optional
              // domain parameters... When omitted, the parameters component
              // MUST be omitted entirely
              // rfc3370 3.1: When the id-dsa-with-sha1 algorithm identifier
              // is used, the AlgorithmIdentifier parameters field MUST be absent.
              /*if (
                  algid.equals((Object)SHA_oid) ||
                  algid.equals((Object)SHA256_oid) ||
                  algid.equals((Object)SHA384_oid) ||
                  algid.equals((Object)SHA512_oid) ||
                  algid.equals((Object)DSA_oid) ||
                  algid.equals((Object)sha1WithDSA_oid)) {
                  ; // no parameter part encoded
              } else {
                  bytes.putNull();
              }*/
              bytes.putNull();
          } else {
              bytes.putDerValue(params);
          }
          tmp.write(DerValue.tag_Sequence, bytes);
          out.write(tmp.toByteArray());
      }
docs: DER encode this object onto an output stream.
  Implements the <code>DerEncoder</code> interface.
  
  @param out
  the output stream on which to write the DER encoding.
  
  @exception IOException on encoding error.