public PrivateKeyEntry(PrivateKey privateKey,
Certificate[] chain) {
if (privateKey == null || chain == null) {
throw new NullPointerException("invalid null input");
}
if (chain.length == 0) {
throw new IllegalArgumentException
("invalid zero-length input chain");
}
Certificate[] clonedChain = chain.clone();
String certType = clonedChain[0].getType();
for (int i = 1; i < clonedChain.length; i++) {
if (!certType.equals(clonedChain[i].getType())) {
throw new IllegalArgumentException
("chain does not contain certificates " +
"of the same type");
}
}
if (!privateKey.getAlgorithm().equals
(clonedChain[0].getPublicKey().getAlgorithm())) {
throw new IllegalArgumentException
("private key algorithm does not match " +
"algorithm of public key in end entity " +
"certificate (at index 0)");
}
this.privKey = privateKey;
if (clonedChain[0] instanceof X509Certificate &&
!(clonedChain instanceof X509Certificate[])) {
this.chain = new X509Certificate[clonedChain.length];
System.arraycopy(clonedChain, 0,
this.chain, 0, clonedChain.length);
} else {
this.chain = clonedChain;
}
}
Parameters:
privateKey - the PrivateKey
chain - an array of Certificate s
representing the certificate chain.
The chain must be ordered and contain a
Certificate at index 0
corresponding to the private key.
Throws:
NullPointerException - if
privateKey or chain
is null
IllegalArgumentException - if the specified chain has a
length of 0, if the specified chain does not contain
Certificate s of the same type,
or if the PrivateKey algorithm
does not match the algorithm of the PublicKey
in the end entity Certificate (at index 0)
- exception:
NullPointerException - if
privateKey or chain
is null
- exception:
IllegalArgumentException - if the specified chain has a
length of 0, if the specified chain does not contain
Certificate s of the same type,
or if the PrivateKey algorithm
does not match the algorithm of the PublicKey
in the end entity Certificate (at index 0)
|