question: public static PrivateKey load ( InputStream is ) throws CryptoException , IOException { byte [ ] streamContents = ReadUtil . readFully ( is ) ; EncryptionType encType = getEncryptionType ( new ByteArrayInputStream ( streamContents ) ) ; if ( encType == null ) { throw new CryptoException ( res . getString ( "NotValidPkcs8.exception.message" ) ) ; } if ( encType == ENCRYPTED ) { throw new PrivateKeyEncryptedException ( res . getString ( "Pkcs8IsEncrypted.exception.message" ) ) ; } byte [ ] pvkBytes = null ; PemInfo pemInfo = PemUtil . decode ( new ByteArrayInputStream ( streamContents ) ) ; if ( pemInfo != null ) { pvkBytes = pemInfo . getContent ( ) ; } if ( pvkBytes == null ) { pvkBytes = streamContents ; } try { String privateKeyAlgorithm = getPrivateKeyAlgorithm ( pvkBytes ) ; PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec ( pvkBytes ) ; KeyFactory keyFactory = KeyFactory . getInstance ( privateKeyAlgorithm ) ; PrivateKey pvk = keyFactory . generatePrivate ( privateKeySpec ) ; return pvk ; } catch ( NoSuchAlgorithmException ex ) { throw new CryptoException ( res . getString ( "NoLoadPkcs8PrivateKey.exception.message" ) , ex ) ; } catch ( InvalidKeySpecException ex ) { throw new CryptoException ( res . getString ( "NoLoadPkcs8PrivateKey.exception.message" ) , ex ) ; } }
target:  Load an unencrypted PKCS #8 private key from the stream. The encoding of the private key may be PEM or DER.