@Override public PublicKey newInstance() throws EncodingException { return KeyPairUtil.decodePublicKey(PemUtil.decode(encodedKey)); } }
@Override public PrivateKey newInstance() throws EncodingException { return KeyPairUtil.decodePrivateKey(PemUtil.decode(encodedKey)); } }
/** * Reads an X.509 certificate from ASN.1 encoded format from the given file. * * @param file File containing an DER or PEM encoded X.509 certificate. * * @return Certificate. * * @throws EncodingException on cert parsing errors. * @throws StreamException on IO errors. */ public static X509Certificate readCertificate(final File file) throws EncodingException, StreamException { return readCertificate(StreamUtil.makeStream(file)); }
/** * Converts an integer into a 4-byte big endian array. * * @param value Integer value to convert. * * @return 4-byte big-endian representation of integer value. */ public static byte[] toBytes(final int value) { final byte[] bytes = new byte[4]; toBytes(value, bytes, 0); return bytes; }
/** * Sets the PEM-encoded public key data. * * @param pemEncodedKey PEM-encoded public key data. */ public void setEncodedKey(final String pemEncodedKey) { if (!PemUtil.isPem(ByteUtil.toBytes(pemEncodedKey))) { throw new IllegalArgumentException("Data is not PEM encoded."); } this.encodedKey = pemEncodedKey; }
/** * Reads an X.509 certificate chain from ASN.1 encoded format from the given file. * * @param file File containing a sequence of PEM or DER encoded certificates or PKCS#7 certificate chain. * * @return Certificate. * * @throws EncodingException on cert parsing errors. * @throws StreamException on IO errors. */ public static X509Certificate[] readCertificateChain(final File file) throws EncodingException, StreamException { return readCertificateChain(StreamUtil.makeStream(file)); }
/** * Reads an encoded private key from an input stream. Both PKCS#8 and OpenSSL "traditional" formats are supported in * DER or PEM encoding. See {@link #decodePrivateKey(byte[])} for supported asymmetric algorithms. The {@link * InputStream} parameter is closed by this method. * * @param in Input stream containing private key data. * * @return Private key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors reading data from file. */ public static PrivateKey readPrivateKey(final InputStream in) throws EncodingException, StreamException { return decodePrivateKey(StreamUtil.readAll(in)); }
/** * Reads a DER or PEM-encoded public key from data in the given stream. The {@link InputStream} parameter is closed by * this method. * * @param in Input stream containing an encoded key. * * @return Public key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors. */ public static PublicKey readPublicKey(final InputStream in) throws EncodingException, StreamException { return decodePublicKey(StreamUtil.readAll(in)); }
@Override public String toString() { return this.id + "_" + CodecUtil.b64(this.data); }
/** * Creates a new hash-based DRBG instance that uses the given digest as the pseudorandom source. * * @param digest Digest algorithm. * @param length Length in bits of values to be produced by DRBG instance. * * @return New DRGB instance. */ public static SP80090DRBG newRBG(final Digest digest, final int length) { return newRBG(digest, length, randomEntropySource(length)); }
/** * Reads all data from the given reader. * * @param reader Reader over character data. * * @return Data read from reader. * * @throws StreamException on stream IO errors. */ public static String readAll(final Reader reader) throws StreamException { return readAll(reader, 1024); }
/** * Reads an X.509 certificate from ASN.1 encoded format in the file at the given location. * * @param path Path to file containing an DER or PEM encoded X.509 certificate. * * @return Certificate. * * @throws EncodingException on cert parsing errors. * @throws StreamException on IO errors. */ public static X509Certificate readCertificate(final String path) throws EncodingException, StreamException { return readCertificate(StreamUtil.makeStream(new File(path))); }
/** * Creates a new instance. Instances of this method produces nonces of the default length, {@value #DEFAULT_LENGTH}, * and are not subject to constraints on the number of invocations. * * @param fixed User-defined fixed field value. * @param invocations Initial invocation count. The invocations field is incremented _before_ use in {@link * #generate()}. */ public CounterNonce(final int fixed, final long invocations) { this(ByteUtil.toBytes(fixed), invocations); }
/** * Sets the PEM-encoded private key data. * * @param pemEncodedKey PEM-encoded private key data. */ public void setEncodedKey(final String pemEncodedKey) { if (!PemUtil.isPem(ByteUtil.toBytes(pemEncodedKey))) { throw new IllegalArgumentException("Data is not PEM encoded."); } this.encodedKey = pemEncodedKey; }
/** * Reads an X.509 certificate chain from ASN.1 encoded format in the file at the given location. * * @param path Path to file containing a sequence of PEM or DER encoded certificates or PKCS#7 certificate chain. * * @return Certificate. * * @throws EncodingException on cert parsing errors. * @throws StreamException on IO errors. */ public static X509Certificate[] readCertificateChain(final String path) throws EncodingException, StreamException { return readCertificateChain(StreamUtil.makeStream(new File(path))); }
/** * Reads an encrypted private key from an input stream. Both PKCS#8 and OpenSSL "traditional" formats are supported in * DER or PEM encoding. See {@link #decodePrivateKey(byte[])} for supported asymmetric algorithms. The {@link * InputStream} parameter is closed by this method. * * @param in Input stream containing private key data. * @param password Password used to encrypt private key. * * @return Private key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors. */ public static PrivateKey readPrivateKey(final InputStream in, final char[] password) throws EncodingException, StreamException { return decodePrivateKey(StreamUtil.readAll(in), password); }
/** * Reads all the data from the given input stream. * * @param input Input stream to read. * * @return Byte array of data read from stream. * * @throws StreamException on stream IO errors. */ public static byte[] readAll(final InputStream input) throws StreamException { return readAll(input, 1024); }
/** * Creates a new instance. * * @param fixed User-defined fixed field value. * @param invocations Initial invocation count. The invocations field is incremented _before_ use in {@link * #generate()}. */ public CounterNonce(final String fixed, final long invocations) { this(ByteUtil.toBytes(fixed), invocations); }
/** * Creates a new instance. * * @param fixed User-defined fixed field value. * @param invocations Initial invocation count. The invocations field is incremented _before_ use in {@link * #generate()}. */ public CounterNonce(final long fixed, final long invocations) { this(ByteUtil.toBytes(fixed), invocations); }
/** * Converts a long integer into an 8-byte big endian array. * * @param value Long integer value to convert. * * @return 8-byte big-endian representation of long integer value. */ public static byte[] toBytes(final long value) { final byte[] bytes = new byte[8]; toBytes(value, bytes, 0); return bytes; }