Class RsaKey
- java.lang.Object
-
- com.microsoft.azure.keyvault.cryptography.RsaKey
-
- All Implemented Interfaces:
IKey
,Closeable
,AutoCloseable
public class RsaKey extends Object implements IKey
-
-
Field Summary
Fields Modifier and Type Field Description static int
KeySize1024
static int
KeySize2048
static int
KeySize4096
-
Constructor Summary
Constructors Constructor Description RsaKey()
Constructor.RsaKey(String kid)
Constructor.RsaKey(String kid, int keySize)
Constructor.RsaKey(String kid, int keySize, Provider provider)
Constructor.RsaKey(String kid, KeyPair keyPair)
Constructor.RsaKey(String kid, KeyPair keyPair, Provider provider)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
com.google.common.util.concurrent.ListenableFuture<byte[]>
decryptAsync(byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, String algorithm)
com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Triple<byte[],byte[],String>>
encryptAsync(byte[] plaintext, byte[] iv, byte[] authenticationData, String algorithm)
static RsaKey
fromJsonWebKey(JsonWebKey jwk)
Converts JSON web key to RsaKey.static RsaKey
fromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters)
Converts JSON web key to RsaKey and include the private key if set to true.static RsaKey
fromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters, Provider provider)
Converts JSON web key to RsaKey and include the private key if set to true.String
getDefaultEncryptionAlgorithm()
static int
getDefaultKeySize()
String
getDefaultKeyWrapAlgorithm()
String
getDefaultSignatureAlgorithm()
KeyPair
getKeyPair()
String
getKid()
com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>>
signAsync(byte[] digest, String algorithm)
JsonWebKey
toJsonWebKey()
Converts RsaKey to JSON web key.com.google.common.util.concurrent.ListenableFuture<byte[]>
unwrapKeyAsync(byte[] encryptedKey, String algorithm)
com.google.common.util.concurrent.ListenableFuture<Boolean>
verifyAsync(byte[] digest, byte[] signature, String algorithm)
com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>>
wrapKeyAsync(byte[] key, String algorithm)
-
-
-
Field Detail
-
KeySize1024
public static final int KeySize1024
- See Also:
- Constant Field Values
-
KeySize2048
public static final int KeySize2048
- See Also:
- Constant Field Values
-
KeySize4096
public static final int KeySize4096
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RsaKey
public RsaKey() throws NoSuchAlgorithmException
Constructor. Generates a new RsaKey with a 2048 size keypair and a randomly generated kid.- Throws:
NoSuchAlgorithmException
-
RsaKey
public RsaKey(String kid) throws NoSuchAlgorithmException
Constructor. Generates a new RsaKey with a 2048 size keypair and the kid given.- Parameters:
kid
-- Throws:
NoSuchAlgorithmException
-
RsaKey
public RsaKey(String kid, int keySize) throws NoSuchAlgorithmException
Constructor. Generates a new RsaKey with size keySize and the kid given.- Parameters:
kid
-keySize
-- Throws:
NoSuchAlgorithmException
-
RsaKey
public RsaKey(String kid, int keySize, Provider provider) throws NoSuchAlgorithmException
Constructor. Generates a new RsaKey with size keySize and the kid given. The given provider is used for algorithm implementation.- Parameters:
kid
-keySize
-provider
- Java security provider.- Throws:
NoSuchAlgorithmException
-
RsaKey
public RsaKey(String kid, KeyPair keyPair)
Constructor. Generates a new RsaKey with the given KeyPair. The keyPair must be an RSAKey.- Parameters:
kid
-keyPair
-
-
-
Method Detail
-
getDefaultKeySize
public static int getDefaultKeySize()
-
fromJsonWebKey
public static RsaKey fromJsonWebKey(JsonWebKey jwk)
Converts JSON web key to RsaKey.- Parameters:
jwk
-- Returns:
- RsaKey
-
fromJsonWebKey
public static RsaKey fromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters)
Converts JSON web key to RsaKey and include the private key if set to true.- Parameters:
jwk
-includePrivateParameters
- true if the RSA key pair should include the private key. False otherwise.- Returns:
- RsaKey
-
fromJsonWebKey
public static RsaKey fromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters, Provider provider)
Converts JSON web key to RsaKey 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:
- RsaKey
-
toJsonWebKey
public JsonWebKey toJsonWebKey()
Converts RsaKey to JSON web key.- Returns:
-
getDefaultEncryptionAlgorithm
public String getDefaultEncryptionAlgorithm()
- Specified by:
getDefaultEncryptionAlgorithm
in interfaceIKey
-
getDefaultKeyWrapAlgorithm
public String getDefaultKeyWrapAlgorithm()
- Specified by:
getDefaultKeyWrapAlgorithm
in interfaceIKey
-
getDefaultSignatureAlgorithm
public String getDefaultSignatureAlgorithm()
- Specified by:
getDefaultSignatureAlgorithm
in interfaceIKey
-
getKeyPair
public KeyPair getKeyPair()
-
decryptAsync
public com.google.common.util.concurrent.ListenableFuture<byte[]> decryptAsync(byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, String algorithm) throws NoSuchAlgorithmException
- Specified by:
decryptAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
encryptAsync
public com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Triple<byte[],byte[],String>> encryptAsync(byte[] plaintext, byte[] iv, byte[] authenticationData, String algorithm) throws NoSuchAlgorithmException
- Specified by:
encryptAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
wrapKeyAsync
public com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>> wrapKeyAsync(byte[] key, String algorithm) throws NoSuchAlgorithmException
- Specified by:
wrapKeyAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
unwrapKeyAsync
public com.google.common.util.concurrent.ListenableFuture<byte[]> unwrapKeyAsync(byte[] encryptedKey, String algorithm) throws NoSuchAlgorithmException
- Specified by:
unwrapKeyAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
signAsync
public com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>> signAsync(byte[] digest, String algorithm) throws NoSuchAlgorithmException
- Specified by:
signAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
verifyAsync
public com.google.common.util.concurrent.ListenableFuture<Boolean> verifyAsync(byte[] digest, byte[] signature, String algorithm) throws NoSuchAlgorithmException
- Specified by:
verifyAsync
in interfaceIKey
- Throws:
NoSuchAlgorithmException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-