本文整理汇总了Java中com.auth0.jwt.interfaces.DecodedJWT.getSignature方法的典型用法代码示例。如果您正苦于以下问题:Java DecodedJWT.getSignature方法的具体用法?Java DecodedJWT.getSignature怎么用?Java DecodedJWT.getSignature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.auth0.jwt.interfaces.DecodedJWT
的用法示例。
在下文中一共展示了DecodedJWT.getSignature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verify
import com.auth0.jwt.interfaces.DecodedJWT; //导入方法依赖的package包/类
@Override
public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
byte[] signatureBytes = null;
String signature = jwt.getSignature();
String urlDecoded = null;
switch (encodeType) {
case Base16:
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = Hex.decodeHex(urlDecoded);
break;
case Base32:
Base32 base32 = new Base32();
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = base32.decode(urlDecoded);
break;
case Base64:
signatureBytes = Base64.decodeBase64(signature);
break;
}
if (signatureBytes.length > 0) {
throw new SignatureVerificationException(this);
}
}
示例2: verify
import com.auth0.jwt.interfaces.DecodedJWT; //导入方法依赖的package包/类
@Override
public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
byte[] contentBytes = String.format("%s.%s", jwt.getHeader(), jwt.getPayload()).getBytes(StandardCharsets.UTF_8);
byte[] signatureBytes = null;
String signature = jwt.getSignature();
String urlDecoded = null;
switch (encodeType) {
case Base16:
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = Hex.decodeHex(urlDecoded);
break;
case Base32:
Base32 base32 = new Base32();
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = base32.decode(urlDecoded);
break;
case Base64:
signatureBytes = Base64.decodeBase64(signature);
break;
}
try {
ECPublicKey publicKey = keyProvider.getPublicKeyById(jwt.getKeyId());
if (publicKey == null) {
throw new IllegalStateException("The given Public Key is null.");
}
boolean valid = crypto.verifySignatureFor(getDescription(), publicKey, contentBytes, JOSEToDER(signatureBytes));
if (!valid) {
throw new SignatureVerificationException(this);
}
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException | IllegalStateException e) {
throw new SignatureVerificationException(this, e);
}
}
示例3: verify
import com.auth0.jwt.interfaces.DecodedJWT; //导入方法依赖的package包/类
@Override
public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
byte[] contentBytes = String.format("%s.%s", jwt.getHeader(), jwt.getPayload()).getBytes(StandardCharsets.UTF_8);
byte[] signatureBytes = null;
String signature = jwt.getSignature();
String urlDecoded = null;
switch (encodeType) {
case Base16:
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = Hex.decodeHex(urlDecoded);
break;
case Base32:
Base32 base32 = new Base32();
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = base32.decode(urlDecoded);
break;
case Base64:
signatureBytes = Base64.decodeBase64(signature);
break;
}
try {
boolean valid = crypto.verifySignatureFor(getDescription(), secret, contentBytes, signatureBytes);
if (!valid) {
throw new SignatureVerificationException(this);
}
} catch (IllegalStateException | InvalidKeyException | NoSuchAlgorithmException e) {
throw new SignatureVerificationException(this, e);
}
}
示例4: verify
import com.auth0.jwt.interfaces.DecodedJWT; //导入方法依赖的package包/类
@Override
public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
byte[] contentBytes = String.format("%s.%s", jwt.getHeader(), jwt.getPayload()).getBytes(StandardCharsets.UTF_8);
byte[] signatureBytes = null;
String signature = jwt.getSignature();
String urlDecoded = null;
switch (encodeType) {
case Base16:
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = Hex.decodeHex(urlDecoded);
break;
case Base32:
Base32 base32 = new Base32();
urlDecoded = URLDecoder.decode(signature, "UTF-8");
signatureBytes = base32.decode(urlDecoded);
break;
case Base64:
signatureBytes = Base64.decodeBase64(signature);
break;
}
try {
RSAPublicKey publicKey = keyProvider.getPublicKeyById(jwt.getKeyId());
if (publicKey == null) {
throw new IllegalStateException("The given Public Key is null.");
}
boolean valid = crypto.verifySignatureFor(getDescription(), publicKey, contentBytes, signatureBytes);
if (!valid) {
throw new SignatureVerificationException(this);
}
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException | IllegalStateException e) {
throw new SignatureVerificationException(this, e);
}
}
示例5: main
import com.auth0.jwt.interfaces.DecodedJWT; //导入方法依赖的package包/类
public static void main(String[] args) throws UnsupportedEncodingException {
DecodedJWT jwt = verifyJWT(createJWT());
String header = jwt.getHeader();
String payload = jwt.getPayload();
String signature = jwt.getSignature();
String jti = jwt.getClaim("jti").asString();
String issuer = jwt.getIssuer();
}