下面列出了io.jsonwebtoken.SignatureAlgorithm#ES256 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Sets the path to a PKCS8 PEM file containing the RSA private key to use for signing tokens asserting the
* registration status of devices.
*
* @param keyPath The absolute path to the file.
* @throws NullPointerException if the path is {@code null}.
* @throws IllegalArgumentException if the key cannot be read from the file.
*/
protected final void setPrivateKey(final String keyPath) {
Objects.requireNonNull(keyPath);
key = KeyLoader.fromFiles(vertx, keyPath, null).getPrivateKey();
if (key == null) {
throw new IllegalArgumentException("cannot load private key: " + keyPath);
} else if (key instanceof ECKey) {
algorithm = SignatureAlgorithm.ES256;
} else if (key instanceof RSAKey) {
algorithm = SignatureAlgorithm.RS256;
} else {
throw new IllegalArgumentException("unsupported private key type: " + key.getClass());
}
}
/**
* Sets the path to a PEM file containing a certificate holding a public key to use for validating the signature of
* tokens asserting the registration status of devices.
*
* @param keyPath The absolute path to the file.
* @throws NullPointerException if the path is {@code null}.
* @throws IllegalArgumentException if the key cannot be read from the file.
*/
protected final void setPublicKey(final String keyPath) {
Objects.requireNonNull(keyPath);
key = KeyLoader.fromFiles(vertx, null, keyPath).getPublicKey();
if (key == null) {
throw new IllegalArgumentException("cannot load public key: " + keyPath);
} else if (key instanceof ECKey) {
algorithm = SignatureAlgorithm.ES256;
} else if (key instanceof RSAKey) {
algorithm = SignatureAlgorithm.RS256;
} else {
throw new IllegalArgumentException("unsupported public key type: " + key.getClass());
}
}
public ServerPrivateKey(final PrivateKey key, final String id) {
this.key = key;
this.id = id;
algorithm = ECDSA.equalsIgnoreCase(key.getAlgorithm()) ?
SignatureAlgorithm.ES256 : SignatureAlgorithm.RS256;
}