private PrivateKey readDERPrivateKey() {
        LOGGER.debug("Attempting to read key as DER [{}]", this.location);
        try (val privKey = this.location.getInputStream()) {
            val bytes = new byte[(int) this.location.contentLength()];
            privKey.read(bytes);
            val privSpec = new PKCS8EncodedKeySpec(bytes);
            val factory = KeyFactory.getInstance(this.algorithm);
            return factory.generatePrivate(privSpec);
        } catch (final Exception e) {
            LOGGER.debug("Unable to read key", e);
            return null;
        }
    }
Factory Bean for creating a private key from a file.

@author Scott Battaglia
@since 3.1
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/crypto/PrivateKeyFactoryBean.java