@PublicAPI public class Credentials extends Object implements Serializable
Stores encapsulated Scheduler credentials as well as metadata used to determine which method should be used for decryption: key generation algorithm, key size, and cipher parameters.
The credentials are encrypted with a symmetric AES key. The AES key is encrypted using an asymmetric public key: the corresponding private key is required to decrypt the secret AES key, and then decrypt the data.
Extensive documentation for these parameters can be found in the Java Cryptography Extension Reference Guide.
KeyPairUtil
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
credentialsPathProperty
Java properly describing the path to the encrypted credentials on the local drive
|
static String |
pubkeyPathProperty
Java property describing the path to the public key on the local drive
|
Modifier and Type | Method and Description |
---|---|
static Credentials |
createCredentials(CredData cc,
PublicKey pubKey)
Creates new encrypted credentials.
|
static Credentials |
createCredentials(CredData cc,
PublicKey pubKey,
String cipher)
Creates new encrypted credentials
|
static Credentials |
createCredentials(CredData cc,
String pubPath)
Creates new encrypted credentials.
|
static Credentials |
createCredentials(String login,
String password,
byte[] datakey,
PublicKey pubKey,
String cipher)
Deprecated.
|
static Credentials |
createCredentials(String login,
String password,
PublicKey pubKey)
Deprecated.
|
static Credentials |
createCredentials(String login,
String password,
String pubPath)
Deprecated.
|
static Credentials |
createCredentials(String login,
String password,
String pubPath,
String cipher)
Deprecated.
|
CredData |
decrypt(PrivateKey privKey)
Decrypts the encapsulated credentials
|
CredData |
decrypt(String privPath)
Decrypts the encapsulated credentials
|
byte[] |
getBase64()
Returns a representation of this credentials as a base64 encoded byte array
|
static Credentials |
getCredentials()
Retrieves a credentials from disk
|
static Credentials |
getCredentials(InputStream is)
Constructs a Credentials given an InputStream
|
static Credentials |
getCredentials(String path)
Retrieves a credentials from disk
|
static Credentials |
getCredentialsBase64(byte[] base64enc)
Creates a Credentials given its base64 encoded representation
|
static String |
getCredentialsPath() |
static PrivateKey |
getPrivateKey(String privPath)
Retrieves a private key stored in a local file
|
static PrivateKey |
getPrivateKey(String privPath,
String[] algorithms)
Retrieves a private key stored in a local file
|
static String |
getPubKeyPath() |
static PublicKey |
getPublicKey(String pubPath)
Retrieves a public key stored in a local file
|
String |
toString() |
void |
writeToDisk(String path)
Write the contents of a Credentials object to the disk
|
public static final String credentialsPathProperty
public static final String pubkeyPathProperty
public void writeToDisk(String path) throws KeyException
Use the current value of the credentialsPathProperty
property to determine the file to which the data will be written
Credentials are written to disk in base64 encoded form.
See getCredentials()
for the inverse operation
path
- file path where the credentials will be written on the diskKeyException
- Unable to locate or open file, IO errorpublic static PublicKey getPublicKey(String pubPath) throws KeyException
pubPath
- path to the public key on the local filesystemKeyException
- the key could not be retrieved or is malformedpublic static PrivateKey getPrivateKey(String privPath) throws KeyException
Tries to guess the algorithm used for keypair generation which
is not included in the file. According to Java Cryptography Specification,
the algorithm can be only one of "RSA" or "DSA", so this method will try using both.
If the algorithm used to generate the key is neither RSA or DSA
(highly unlikely), this method cannot recreate the private key, but decrypt(String)
maybe will.
privPath
- path to the private key on the local filesystemKeyException
- the key could not be retrieved or is malformed, or the algorithm used
for generation is different from the ones used by this methodpublic static PrivateKey getPrivateKey(String privPath, String[] algorithms) throws KeyException
Tries to guess the algorithm used for keypair generation which
is not included in the file. According to Java Cryptography Specification,
the algorithm can be only one of "RSA" or "DSA", so we can just try both using the
algorithms
param. If the algorithm used to generate the key is neither RSA or DSA
(highly unlikely), this method cannot recreate the private key, but decrypt(String)
maybe will.
privPath
- path to the private key on the local filesystemalgorithms
- a list of algorithms to try for creating the PK. Recommanded value:
{"RSA","DSA"}KeyException
- the key could not be retrieved or is malformed, or the algorithm used for generation
is not one of algorithms
public static Credentials getCredentials() throws KeyException
See writeToDisk(String)
for details on how information is
stored on disk.
credentialsPathProperty
KeyException
- Credentials could not be recoveredpublic static Credentials getCredentials(String path) throws KeyException
See writeToDisk(String)
for details on how information is
stored on disk.
path
- to the file in which credentials are storedpath
KeyException
- Credentials could not be recoveredpublic static Credentials getCredentials(InputStream is) throws KeyException, IOException
is
- contains the base64 representation of a Credentials upon readKeyException
- the Credentials data was read but could not be reconstructedIOException
- the Credentials data could not be read from the streampublic static Credentials getCredentialsBase64(byte[] base64enc) throws KeyException
base64enc
- the Credentials representation as a base64 encoded byte array,
as returned by getBase64()
base64en
representationKeyException
public byte[] getBase64() throws KeyException
Prior to base64 encoding, format is the following:
size / 8
bytes
KeyException
public static String getCredentialsPath()
public static String getPubKeyPath()
public static Credentials createCredentials(CredData cc, String pubPath) throws KeyException
cc
- the data to be encryptedpubPath
- path to the public keyKeyException
- key generation or encryption failedpublic static Credentials createCredentials(CredData cc, PublicKey pubKey) throws KeyException
cc
- the data to be encryptedpubKey
- the public keyKeyException
- key generation or encryption failedpublic static Credentials createCredentials(CredData cc, PublicKey pubKey, String cipher) throws KeyException
Encrypts the message 'credData
' using the
public key pubKey
and cipher
and store it in a new Credentials object.
cc,
- the class containing the data to be cryptedpubKey
- public key used for encryptioncipher
- cipher parameters: combination of transformationsKeyException
- key generation or encryption failedKeyPairUtil.encrypt(PublicKey, String, byte[])
public CredData decrypt(String privPath) throws KeyException
privPath
- path to the private key fileKeyException
- decryption failure, malformed dataKeyPairUtil.decrypt(PrivateKey, String, byte[])
public CredData decrypt(PrivateKey privKey) throws KeyException
privKey
- the private keyKeyException
- decryption failure, malformed dataKeyPairUtil.decrypt(PrivateKey, String, byte[])
@Deprecated public static Credentials createCredentials(String login, String password, String pubPath) throws KeyException
login
- the login to encryptpassword
- the corresponding password to encryptpubPath
- path to the public keyKeyException
- key generation or encryption failed@Deprecated public static Credentials createCredentials(String login, String password, PublicKey pubKey) throws KeyException
login
- the login to encryptpassword
- the corresponding password to encryptpubKey
- the public keyKeyException
- key generation or encryption failed@Deprecated public static Credentials createCredentials(String login, String password, String pubPath, String cipher) throws KeyException
Encrypts the message 'login
:password
' using the
public key at pubPath
and cipher
and store it in a new Credentials object.
login
- the login to encryptpassword
- the corresponding password to encryptpubPath
- path to the public key used for encryptioncipher
- cipher parameters: combination of transformationsKeyException
- key generation or encryption failedKeyPairUtil.encrypt(PublicKey, String, byte[])
@Deprecated public static Credentials createCredentials(String login, String password, byte[] datakey, PublicKey pubKey, String cipher) throws KeyException
Encrypts the message 'login
:password
' using the
public key pubKey
and cipher
and store it in a new Credentials object.
login
- the login to encryptpassword
- the corresponding password to encryptpubKey
- public key used for encryptioncipher
- cipher parameters: combination of transformationsKeyException
- key generation or encryption failedKeyPairUtil.encrypt(PublicKey, String, byte[])