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 intKeySize1024static intKeySize2048static intKeySize4096
-
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 voidclose()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 RsaKeyfromJsonWebKey(JsonWebKey jwk)Converts JSON web key to RsaKey.static RsaKeyfromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters)Converts JSON web key to RsaKey and include the private key if set to true.static RsaKeyfromJsonWebKey(JsonWebKey jwk, boolean includePrivateParameters, Provider provider)Converts JSON web key to RsaKey and include the private key if set to true.StringgetDefaultEncryptionAlgorithm()static intgetDefaultKeySize()StringgetDefaultKeyWrapAlgorithm()StringgetDefaultSignatureAlgorithm()KeyPairgetKeyPair()StringgetKid()com.google.common.util.concurrent.ListenableFuture<org.apache.commons.lang3.tuple.Pair<byte[],String>>signAsync(byte[] digest, String algorithm)JsonWebKeytoJsonWebKey()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 NoSuchAlgorithmExceptionConstructor. 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:
getDefaultEncryptionAlgorithmin interfaceIKey
-
getDefaultKeyWrapAlgorithm
public String getDefaultKeyWrapAlgorithm()
- Specified by:
getDefaultKeyWrapAlgorithmin interfaceIKey
-
getDefaultSignatureAlgorithm
public String getDefaultSignatureAlgorithm()
- Specified by:
getDefaultSignatureAlgorithmin 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:
decryptAsyncin 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:
encryptAsyncin 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:
wrapKeyAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
unwrapKeyAsync
public com.google.common.util.concurrent.ListenableFuture<byte[]> unwrapKeyAsync(byte[] encryptedKey, String algorithm) throws NoSuchAlgorithmException- Specified by:
unwrapKeyAsyncin 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:
signAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
verifyAsync
public com.google.common.util.concurrent.ListenableFuture<Boolean> verifyAsync(byte[] digest, byte[] signature, String algorithm) throws NoSuchAlgorithmException
- Specified by:
verifyAsyncin interfaceIKey- Throws:
NoSuchAlgorithmException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-