Class JsonWebKey
- java.lang.Object
-
- com.azure.security.keyvault.keys.models.JsonWebKey
-
public class JsonWebKey extends Object
As of http://tools.ietf.org/html/draft-ietf-jose-json-web-key-18.
-
-
Constructor Summary
Constructors Constructor Description JsonWebKey()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearMemory()Clear key materials.booleanequals(JsonWebKey jwk)Indicates whether some otherJsonWebKeyis "equal to" this one.booleanequals(Object obj)static JsonWebKeyfromAes(SecretKey secretKey)Converts AES key to JSON web key.static JsonWebKeyfromAes(SecretKey secretKey, List<KeyOperation> keyOperations)Converts AES key to JSON web key.static JsonWebKeyfromEc(KeyPair keyPair, Provider provider)Converts EC key pair to JSON web key.static JsonWebKeyfromEc(KeyPair keyPair, Provider provider, List<KeyOperation> keyOperations)Converts EC key pair to JSON web key.static JsonWebKeyfromRsa(KeyPair keyPair)Converts RSA key pair to JSON web key.static JsonWebKeyfromRsa(KeyPair keyPair, List<KeyOperation> keyOperations)Converts RSA key pair to JSON web key.KeyCurveNamegetCurveName()Get the crv value.byte[]getD()Get the d value.byte[]getDp()Get the RSA Private Key Parameter value.byte[]getDq()Get the RSA Private Key Parameter value.byte[]getE()Get the e value.StringgetId()Get the kid value.byte[]getK()Get Symmetric key value.List<KeyOperation>getKeyOps()Get the immutable key operations list.KeyTypegetKeyType()Get the kty value.byte[]getN()Get the n value.byte[]getP()Get the RSA secret prime value.byte[]getQ()Get RSA secret prime, with p < q value.byte[]getQi()Get the RSA Private Key Parameter value.byte[]getT()Get HSM Token value, used with Bring Your Own Key.byte[]getX()Get the x value.byte[]getY()Get the y value.inthashCode()booleanhasPrivateKey()Verifies whether theJsonWebKeyhas private key.booleanisValid()Verifies whether theJsonWebKeyis valid.JsonWebKeysetCurveName(KeyCurveName crv)Set the crv value.JsonWebKeysetD(byte[] d)Set the d value.JsonWebKeysetDp(byte[] dp)Set RSA Private Key Parameter value.JsonWebKeysetDq(byte[] dq)Set RSA Private Key Parameter value .JsonWebKeysetE(byte[] e)Set the e value.JsonWebKeysetId(String keyId)Set the key identifier value.JsonWebKeysetK(byte[] k)Set the Symmetric key value.JsonWebKeysetKeyOps(List<KeyOperation> keyOps)Set the keyOps value.JsonWebKeysetKeyType(KeyType keyType)Set the key type value.JsonWebKeysetN(byte[] n)Set the n value.JsonWebKeysetP(byte[] p)Set the RSA secret prime value.JsonWebKeysetQ(byte[] q)Set the RSA secret prime, with p < q value.JsonWebKeysetQi(byte[] qi)Set RSA Private Key Parameter value.JsonWebKeysetT(byte[] t)Set HSM Token value, used with Bring Your Own Key.JsonWebKeysetX(byte[] x)Set the x value.JsonWebKeysetY(byte[] y)Set the y value.SecretKeytoAes()Converts JSON web key to AES key.KeyPairtoEc()Converts JSON web key to EC key pair and include the private key if set to true.KeyPairtoEc(boolean includePrivateParameters)Converts JSON web key to EC key pair and include the private key if set to true.KeyPairtoEc(boolean includePrivateParameters, Provider provider)Converts JSON web key to EC key pair and include the private key if set to true.KeyPairtoRsa()Converts JSON web key to RSA key pair.KeyPairtoRsa(boolean includePrivateParameters)Converts JSON web key to RSA key pair and include the private key if set to true.KeyPairtoRsa(boolean includePrivateParameters, Provider provider)Converts JSON web key to RSA key pair and include the private key if set to true.StringtoString()
-
-
-
Method Detail
-
getId
public String getId()
Get the kid value.- Returns:
- the kid value
-
setId
public JsonWebKey setId(String keyId)
Set the key identifier value.- Parameters:
keyId- The keyId value to set- Returns:
- the JsonWebKey object itself.
-
getKeyType
public KeyType getKeyType()
Get the kty value.- Returns:
- the kty value
-
setKeyType
public JsonWebKey setKeyType(KeyType keyType)
Set the key type value.- Parameters:
keyType- The key type- Returns:
- the JsonWebKey object itself.
-
getKeyOps
public List<KeyOperation> getKeyOps()
Get the immutable key operations list. The list cannot be modified.- Returns:
- the key operations list
-
setKeyOps
public JsonWebKey setKeyOps(List<KeyOperation> keyOps)
Set the keyOps value.- Parameters:
keyOps- The keyOps value to set- Returns:
- the JsonWebKey object itself.
-
getN
public byte[] getN()
Get the n value.- Returns:
- the n value
-
setN
public JsonWebKey setN(byte[] n)
Set the n value.- Parameters:
n- The n value to set- Returns:
- the JsonWebKey object itself.
-
getE
public byte[] getE()
Get the e value.- Returns:
- the e value
-
setE
public JsonWebKey setE(byte[] e)
Set the e value.- Parameters:
e- The e value to set- Returns:
- the JsonWebKey object itself.
-
getD
public byte[] getD()
Get the d value.- Returns:
- the d value
-
setD
public JsonWebKey setD(byte[] d)
Set the d value.- Parameters:
d- The d value to set- Returns:
- the JsonWebKey object itself.
-
getDp
public byte[] getDp()
Get the RSA Private Key Parameter value.- Returns:
- the RSA Private Key Parameter value.
-
setDp
public JsonWebKey setDp(byte[] dp)
Set RSA Private Key Parameter value.- Parameters:
dp- The RSA Private Key Parameter value to set.- Returns:
- the JsonWebKey object itself.
-
getDq
public byte[] getDq()
Get the RSA Private Key Parameter value.- Returns:
- the RSA Private Key Parameter value.
-
setDq
public JsonWebKey setDq(byte[] dq)
Set RSA Private Key Parameter value .- Parameters:
dq- The RSA Private Key Parameter value to set.- Returns:
- the JsonWebKey object itself.
-
getQi
public byte[] getQi()
Get the RSA Private Key Parameter value.- Returns:
- the RSA Private Key Parameter value.
-
setQi
public JsonWebKey setQi(byte[] qi)
Set RSA Private Key Parameter value.- Parameters:
qi- The RSA Private Key Parameter value to set.- Returns:
- the JsonWebKey object itself.
-
getP
public byte[] getP()
Get the RSA secret prime value.- Returns:
- the RSA secret prime value.
-
setP
public JsonWebKey setP(byte[] p)
Set the RSA secret prime value.- Parameters:
p- The RSA secret prime value.- Returns:
- the JsonWebKey object itself.
-
getQ
public byte[] getQ()
Get RSA secret prime, with p < q value.- Returns:
- the RSA secret prime, with p < q value.
-
setQ
public JsonWebKey setQ(byte[] q)
Set the RSA secret prime, with p < q value.- Parameters:
q- The the RSA secret prime, with p < q value to be set.- Returns:
- the JsonWebKey object itself.
-
getK
public byte[] getK()
Get Symmetric key value.- Returns:
- the symmetric key value.
-
setK
public JsonWebKey setK(byte[] k)
Set the Symmetric key value.- Parameters:
k- The symmetric key value to set.- Returns:
- the JsonWebKey object itself.
-
getT
public byte[] getT()
Get HSM Token value, used with Bring Your Own Key.- Returns:
- HSM Token, used with Bring Your Own Key.
-
setT
public JsonWebKey setT(byte[] t)
Set HSM Token value, used with Bring Your Own Key.- Parameters:
t- The HSM Token value to set, used with Bring Your Own Key- Returns:
- the JsonWebKey object itself.
-
getCurveName
public KeyCurveName getCurveName()
Get the crv value.- Returns:
- the crv value
-
setCurveName
public JsonWebKey setCurveName(KeyCurveName crv)
Set the crv value.- Parameters:
crv- The crv value to set- Returns:
- the JsonWebKey object itself.
-
getX
public byte[] getX()
Get the x value.- Returns:
- the x value
-
setX
public JsonWebKey setX(byte[] x)
Set the x value.- Parameters:
x- The x value to set- Returns:
- the JsonWebKey object itself.
-
getY
public byte[] getY()
Get the y value.- Returns:
- the y value
-
setY
public JsonWebKey setY(byte[] y)
Set the y value.- Parameters:
y- The y value to set- Returns:
- the JsonWebKey object itself.
-
fromRsa
public static JsonWebKey fromRsa(KeyPair keyPair)
Converts RSA key pair to JSON web key.- Parameters:
keyPair- Tbe RSA key pair- Returns:
- the JSON web key, converted from RSA key pair.
-
fromRsa
public static JsonWebKey fromRsa(KeyPair keyPair, List<KeyOperation> keyOperations)
Converts RSA key pair to JSON web key.- Parameters:
keyPair- Tbe RSA key pairkeyOperations- The key operations to set on the key- Returns:
- the JSON web key, converted from RSA key pair.
-
toRsa
public KeyPair toRsa()
Converts JSON web key to RSA key pair.- Returns:
- RSA key pair
-
toRsa
public KeyPair toRsa(boolean includePrivateParameters)
Converts JSON web key to RSA key pair and include the private key if set to true.- Parameters:
includePrivateParameters- true if the RSA key pair should include the private key. False otherwise.- Returns:
- RSA key pair
-
toRsa
public KeyPair toRsa(boolean includePrivateParameters, Provider provider)
Converts JSON web key to RSA key pair and include the private key if set to true.- Parameters:
provider- The Java security provider.includePrivateParameters- true if the RSA key pair should include the private key. False otherwise.- Returns:
- RSA key pair
-
toEc
public KeyPair toEc()
Converts JSON web key to EC key pair and include the private key if set to true.- Returns:
- EC key pair
-
toEc
public KeyPair toEc(boolean includePrivateParameters)
Converts JSON web key to EC key pair and include the private key if set to true.- Parameters:
includePrivateParameters- true if the EC key pair should include the private key. False otherwise.- Returns:
- EC key pair
-
toEc
public KeyPair toEc(boolean includePrivateParameters, Provider provider)
Converts JSON web key to EC key pair and include the private key if set to true.- Parameters:
includePrivateParameters- true if the EC key pair should include the private key. False otherwise.provider- The Java security provider- Returns:
- EC key pair
- Throws:
IllegalArgumentException- if the key type is not EC or EC HSMIllegalStateException- if an instance of EC key pair cannot be generated
-
fromEc
public static JsonWebKey fromEc(KeyPair keyPair, Provider provider)
Converts EC key pair to JSON web key.- Parameters:
keyPair- The EC key pairprovider- The Java security provider- Returns:
- the JSON web key, converted from EC key pair.
-
fromEc
public static JsonWebKey fromEc(KeyPair keyPair, Provider provider, List<KeyOperation> keyOperations)
Converts EC key pair to JSON web key.- Parameters:
keyPair- The EC key pairprovider- The Java security providerkeyOperations- The key operations to set.- Returns:
- the JSON web key, converted from EC key pair.
-
fromAes
public static JsonWebKey fromAes(SecretKey secretKey)
Converts AES key to JSON web key.- Parameters:
secretKey- The AES key- Returns:
- the JSON web key, converted from AES key.
-
fromAes
public static JsonWebKey fromAes(SecretKey secretKey, List<KeyOperation> keyOperations)
Converts AES key to JSON web key.- Parameters:
secretKey- The AES keykeyOperations- The key operations to set- Returns:
- the JSON web key, converted from AES key.
-
toAes
public SecretKey toAes()
Converts JSON web key to AES key.- Returns:
- AES key
-
equals
public boolean equals(JsonWebKey jwk)
Indicates whether some otherJsonWebKeyis "equal to" this one.- Parameters:
jwk- The otherJsonWebKeyto compare with.- Returns:
- true if this
JsonWebKeyis the same as the jwk argument; false otherwise.
-
hasPrivateKey
public boolean hasPrivateKey()
Verifies whether theJsonWebKeyhas private key.- Returns:
- true if the
JsonWebKeyhas private key; false otherwise.
-
isValid
public boolean isValid()
Verifies whether theJsonWebKeyis valid.- Returns:
- true if the
JsonWebKeyis valid; false otherwise.
-
clearMemory
public void clearMemory()
Clear key materials.
-
-