title: Decode DER-encoded valued from X500Name
body: <p>I have a <code>java.security.util.DerValue</code> that I retrive from X500Name.</p>
  
  <pre><code>x500Name.findMostSpecificAttribute(SOME_OID)
  </code></pre>
  
  <p>Some values stored as DER-encoded. <code>.toString</code> returns me something lile: </p>
  
  <pre><code>[DerValue, tag = 18, length = 12]
  </code></pre>
  
  <p>How to decode it? </p>
  
  <p>Also, it's not possible to get bytes[] from it. </p>
  
  <pre><code>derValue.getOctetString
  </code></pre>
  
  <p>returns me </p>
  
  <pre><code>java.io.IOException: DerValue.getOctetString, not an Octet String: 18
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>My solution is: </p>
  
  <pre><code>def decodeDERValue(derValue: DerValue): String = {
      val asnInput = new ASN1InputStream(new ByteArrayInputStream(derValue.toByteArray))
  
      val obj = asnInput.readObject()
      val derValueSting = obj match {
        case p: DERPrintableString =&gt; p.getString
        case p: DERUTF8String =&gt; p.getString
        case p: DERIA5String =&gt; p.getString
        case _ =&gt; ASN1Dump.dumpAsString(obj, true)
      }
     asnInput.close()
  
     derValueSting.trim
  }
  </code></pre>