Skip to content

Commit

Permalink
Update document and remove deprecation notice for content sign methods (
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj authored Mar 16, 2022
1 parent 1433810 commit e7cae2b
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 14 deletions.
3 changes: 1 addition & 2 deletions lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,13 @@ public byte[] sign(byte[] headerBytes, byte[] payloadBytes) throws SignatureGene

/**
* Sign the given content using this Algorithm instance.
* To get the correct JWT Signature, ensure the content is in the format {HEADER}.{PAYLOAD}
*
* @param contentBytes an array of bytes representing the base64 encoded content to be verified against the signature.
* @return the signature in a base64 encoded array of bytes
* @throws SignatureGenerationException if the Key is invalid.
* @deprecated Please use the {@linkplain #sign(byte[], byte[])} method instead.
*/

@Deprecated
public abstract byte[] sign(byte[] contentBytes) throws SignatureGenerationException;

}
12 changes: 4 additions & 8 deletions lib/src/main/java/com/auth0/jwt/algorithms/CryptoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ byte[] createSignatureFor(String algorithm, PrivateKey privateKey, byte[] header

/**
* Verify signature.
* For valid verification, ensure the content is in the format {HEADER}.{PAYLOAD}
*
* @param algorithm algorithm name.
* @param secretBytes algorithm secret.
Expand All @@ -139,27 +140,24 @@ byte[] createSignatureFor(String algorithm, PrivateKey privateKey, byte[] header
* @return true if signature is valid.
* @throws NoSuchAlgorithmException if the algorithm is not supported.
* @throws InvalidKeyException if the given key is inappropriate for initializing the specified algorithm.
* @deprecated rather use corresponding method which takes header and payload as separate inputs
*/

@Deprecated
boolean verifySignatureFor(String algorithm, byte[] secretBytes, byte[] contentBytes, byte[] signatureBytes) throws NoSuchAlgorithmException, InvalidKeyException {
return MessageDigest.isEqual(createSignatureFor(algorithm, secretBytes, contentBytes), signatureBytes);
}

/**
* Create signature.
* To get the correct JWT Signature, ensure the content is in the format {HEADER}.{PAYLOAD}
*
* @param algorithm algorithm name.
* @param secretBytes algorithm secret.
* @param contentBytes the content to be signed.
* @return the signature bytes.
* @throws NoSuchAlgorithmException if the algorithm is not supported.
* @throws InvalidKeyException if the given key is inappropriate for initializing the specified algorithm.
* @deprecated rather use corresponding method which takes header and payload as separate inputs
*/

@Deprecated
byte[] createSignatureFor(String algorithm, byte[] secretBytes, byte[] contentBytes) throws NoSuchAlgorithmException, InvalidKeyException {
final Mac mac = Mac.getInstance(algorithm);
mac.init(new SecretKeySpec(secretBytes, algorithm));
Expand All @@ -168,6 +166,7 @@ byte[] createSignatureFor(String algorithm, byte[] secretBytes, byte[] contentBy

/**
* Verify signature using a public key.
* For valid verification, ensure the content is in the format {HEADER}.{PAYLOAD}
*
* @param algorithm algorithm name.
* @param publicKey algorithm public key.
Expand All @@ -177,10 +176,8 @@ byte[] createSignatureFor(String algorithm, byte[] secretBytes, byte[] contentBy
* @throws NoSuchAlgorithmException if the algorithm is not supported.
* @throws InvalidKeyException if the given key is inappropriate for initializing the specified algorithm.
* @throws SignatureException if this signature object is not initialized properly or if this signature algorithm is unable to process the input data provided.
* @deprecated rather use corresponding method which takes header and payload as separate inputs
*/

@Deprecated
boolean verifySignatureFor(String algorithm, PublicKey publicKey, byte[] contentBytes, byte[] signatureBytes) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
final Signature s = Signature.getInstance(algorithm);
s.initVerify(publicKey);
Expand All @@ -190,6 +187,7 @@ boolean verifySignatureFor(String algorithm, PublicKey publicKey, byte[] content

/**
* Create signature using a private key.
* To get the correct JWT Signature, ensure the content is in the format {HEADER}.{PAYLOAD}
*
* @param algorithm algorithm name.
* @param privateKey the private key to use for signing.
Expand All @@ -198,10 +196,8 @@ boolean verifySignatureFor(String algorithm, PublicKey publicKey, byte[] content
* @throws NoSuchAlgorithmException if the algorithm is not supported.
* @throws InvalidKeyException if the given key is inappropriate for initializing the specified algorithm.
* @throws SignatureException if this signature object is not initialized properly or if this signature algorithm is unable to process the input data provided.
* @deprecated rather use corresponding method which takes header and payload as separate inputs
*/

@Deprecated
byte[] createSignatureFor(String algorithm, PrivateKey privateKey, byte[] contentBytes) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
final Signature s = Signature.getInstance(algorithm);
s.initSign(privateKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public byte[] sign(byte[] headerBytes, byte[] payloadBytes) throws SignatureGene
}

@Override
@Deprecated
public byte[] sign(byte[] contentBytes) throws SignatureGenerationException {
try {
ECPrivateKey privateKey = keyProvider.getPrivateKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public byte[] sign(byte[] headerBytes, byte[] payloadBytes) throws SignatureGene
}

@Override
@Deprecated
public byte[] sign(byte[] contentBytes) throws SignatureGenerationException {
try {
return crypto.createSignatureFor(getDescription(), secret, contentBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public byte[] sign(byte[] headerBytes, byte[] payloadBytes) throws SignatureGene
}

@Override
@Deprecated
public byte[] sign(byte[] contentBytes) throws SignatureGenerationException {
return new byte[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void verify(DecodedJWT jwt) throws SignatureVerificationException {
}

@Override
@Deprecated
public byte[] sign(byte[] headerBytes, byte[] payloadBytes) throws SignatureGenerationException {
try {
RSAPrivateKey privateKey = keyProvider.getPrivateKey();
Expand Down

0 comments on commit e7cae2b

Please sign in to comment.