public final class RSAKeyPairGenerator extends Object implements RSAKeyPairGeneratorInterface
RSAKeyPairGeneratorInterface.GeneratedClassDescriptor| Constructor and Description |
|---|
RSAKeyPairGenerator() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
arrayToCodeString(int[] values,
String type)
Takes an array of integer-representable primitives (
byte, char, short, int)
and returns a Java code array-literal instantiation of the array, with values in hexadecimal literal format. |
protected int[] |
byteArrayToIntArray(byte[] array)
Converts a
byte array to an int array. |
protected int[] |
charArrayToIntArray(char[] array)
Converts a
char array to an int array. |
protected String |
generateJavaCode(String packageName,
String className,
String interfaceName,
String[] imports,
String methodSignature,
String returnValue)
Generates a final, compilable Java class implementing the specified interface with a single, one-statement
method that returns a simple value.
|
KeyPair |
generateKeyPair()
Generates a key pair with RSA 2048-bit security.
|
void |
saveKeyPairToFiles(KeyPair keyPair,
String privateOutputFileName,
String publicOutputFileName,
char[] password)
Saves the key pair specified to output files specified, encrypting both with the specified password.
|
void |
saveKeyPairToFiles(KeyPair keyPair,
String privateOutputFileName,
String publicOutputFileName,
char[] privatePassword,
char[] publicPassword)
Saves the key pair specified to output files specified, encrypting each with their specified passwords.
|
void |
saveKeyPairToProviders(KeyPair keyPair,
RSAKeyPairGeneratorInterface.GeneratedClassDescriptor privateKeyProvider,
RSAKeyPairGeneratorInterface.GeneratedClassDescriptor publicKeyProvider,
char[] password)
Saves the public and private keys specified to the respective
javaFileContents fields in
the provided RSAKeyPairGeneratorInterface.GeneratedClassDescriptors, encrypting both with the specified
password. |
void |
saveKeyPairToProviders(KeyPair keyPair,
RSAKeyPairGeneratorInterface.GeneratedClassDescriptor privateKeyProvider,
RSAKeyPairGeneratorInterface.GeneratedClassDescriptor publicKeyProvider,
char[] privatePassword,
char[] publicPassword)
Saves the public and private keys specified to the respective
javaFileContents fields in
the provided RSAKeyPairGeneratorInterface.GeneratedClassDescriptors, encrypting each with their
respective passwords. |
void |
savePasswordToProvider(char[] password,
RSAKeyPairGeneratorInterface.GeneratedClassDescriptor passwordProvider)
Saves the password specified to the
javaFileContents field in
the provided RSAKeyPairGeneratorInterface.GeneratedClassDescriptor. |
public KeyPair generateKeyPair() throws RSA2048NotSupportedException
generateKeyPair in interface RSAKeyPairGeneratorInterfaceRSA2048NotSupportedException - if RSA or 2048-bit encryption are not supported.public void saveKeyPairToFiles(KeyPair keyPair, String privateOutputFileName, String publicOutputFileName, char[] password) throws IOException, AlgorithmNotSupportedException, InappropriateKeyException, InappropriateKeySpecificationException
saveKeyPairToFiles in interface RSAKeyPairGeneratorInterfacekeyPair - The key pair to save to the files specifiedprivateOutputFileName - The name of the file to save the encrypted private key topublicOutputFileName - The name of the file to save the encrypted public key topassword - The password to encrypt both keys withIOException - if an error occurs while writing to the files.AlgorithmNotSupportedException - If the encryption algorithm is not supportedInappropriateKeyException - If the public or private keys are invalidInappropriateKeySpecificationException - If the public or private keys are invalidpublic void saveKeyPairToFiles(KeyPair keyPair, String privateOutputFileName, String publicOutputFileName, char[] privatePassword, char[] publicPassword) throws IOException, AlgorithmNotSupportedException, InappropriateKeyException, InappropriateKeySpecificationException
saveKeyPairToFiles in interface RSAKeyPairGeneratorInterfacekeyPair - The key pair to save to the files specifiedprivateOutputFileName - The name of the file to save the encrypted private key topublicOutputFileName - The name of the file to save the encrypted public key toprivatePassword - The password to encrypt the private key withpublicPassword - The password to encrypt the public key withIOException - if an error occurs while writing to the files.AlgorithmNotSupportedException - If the encryption algorithm is not supportedInappropriateKeyException - If the public or private keys are invalidInappropriateKeySpecificationException - If the public or private keys are invalidpublic void saveKeyPairToProviders(KeyPair keyPair, RSAKeyPairGeneratorInterface.GeneratedClassDescriptor privateKeyProvider, RSAKeyPairGeneratorInterface.GeneratedClassDescriptor publicKeyProvider, char[] password) throws AlgorithmNotSupportedException, InappropriateKeyException, InappropriateKeySpecificationException
javaFileContents fields in
the provided RSAKeyPairGeneratorInterface.GeneratedClassDescriptors, encrypting both with the specified
password.saveKeyPairToProviders in interface RSAKeyPairGeneratorInterfacekeyPair - The key pair to saveprivateKeyProvider - An object describing the PrivateKeyDataProvider class to generate, and into which the generated code will be savedpublicKeyProvider - An object describing the PublicKeyDataProvider class to generate, and into which the generated code will be savedpassword - The password to encrypt the keys withAlgorithmNotSupportedException - If the encryption algorithm is not supportedInappropriateKeyException - If the public or private keys are invalidInappropriateKeySpecificationException - If the public or private keys are invalidpublic void saveKeyPairToProviders(KeyPair keyPair, RSAKeyPairGeneratorInterface.GeneratedClassDescriptor privateKeyProvider, RSAKeyPairGeneratorInterface.GeneratedClassDescriptor publicKeyProvider, char[] privatePassword, char[] publicPassword) throws AlgorithmNotSupportedException, InappropriateKeyException, InappropriateKeySpecificationException
javaFileContents fields in
the provided RSAKeyPairGeneratorInterface.GeneratedClassDescriptors, encrypting each with their
respective passwords.saveKeyPairToProviders in interface RSAKeyPairGeneratorInterfacekeyPair - The key pair to saveprivateKeyProvider - An object describing the PrivateKeyDataProvider class to generate, and into which the generated code will be savedpublicKeyProvider - An object describing the PublicKeyDataProvider class to generate, and into which the generated code will be savedprivatePassword - The password to encrypt the private key withpublicPassword - The password to encrypt the public key withAlgorithmNotSupportedException - If the encryption algorithm is not supportedInappropriateKeyException - If the public or private keys are invalidInappropriateKeySpecificationException - If the public or private keys are invalidpublic void savePasswordToProvider(char[] password,
RSAKeyPairGeneratorInterface.GeneratedClassDescriptor passwordProvider)
javaFileContents field in
the provided RSAKeyPairGeneratorInterface.GeneratedClassDescriptor.savePasswordToProvider in interface RSAKeyPairGeneratorInterfacepassword - The password to save to the specified Java classpasswordProvider - An object describing the PasswordProvider class to generate, and into which the generated code will be savedprotected String generateJavaCode(String packageName, String className, String interfaceName, String[] imports, String methodSignature, String returnValue)
packageName - The package name the class should be contained in, or null if no packageclassName - The name of the class to createinterfaceName - The interface this class should implement, or null if no interfaceimports - An array of classes to import at the top of the Java codemethodSignature - The signature of the sole method in the classreturnValue - The statement that the method should return (will be prepended with "return ")protected String arrayToCodeString(int[] values, String type)
byte, char, short, int)
and returns a Java code array-literal instantiation of the array, with values in hexadecimal literal format.
It is the user's responsibility to ensure that the values contained in the array can fit within the smaller
precision of the array type, if applicable.values - The array of values to include in the array codetype - The data type (byte, char, short, int) of the array to returnprotected int[] byteArrayToIntArray(byte[] array)
byte array to an int array.array - The byte array to convertint array.protected int[] charArrayToIntArray(char[] array)
char array to an int array.array - The char array to convertint array.Copyright © 2010-2013 NWTS Java Code. All Rights Reserved. Licensed Under the Apache License version 2.0.