public class OSymmetricKey extends Object
Static creation methods are provided for each type: OSymmetricKey.fromConfig() OSymmetricKey.fromString() OSymmetricKey.fromFile() OSymmetricKey.fromStream() OSymmetricKey.fromKeystore()
The encrypt() methods return a specialized Base64-encoded JSON document with these properties (depending on the cipher transform): "algorithm", "transform", "iv", "payload"
The decrypt() and decryptAsString() methods accept the Base64-encoded JSON document.
A symmetric key credential interceptor is provided (OSymmetricKeyCI) as well as several authenticators: OSecuritySymmetricKeyAuth, OSystemSymmetricKeyAuth
Constructor and Description |
---|
OSymmetricKey() |
OSymmetricKey(SecretKey secretKey)
Uses the specified SecretKey as the private key and sets key algorithm from the SecretKey.
|
OSymmetricKey(String algorithm,
String base64Key)
Sets the SecretKey based on the specified algorithm and Base64 key specified.
|
OSymmetricKey(String secretKeyAlgorithm,
String cipherTransform,
int keySize)
Creates a key based on the algorithm, transformation, and key size specified.
|
Modifier and Type | Method and Description |
---|---|
protected static byte[] |
convertFromBase64(String base64) |
protected static String |
convertToBase64(byte[] bytes) |
protected void |
create() |
byte[] |
decrypt(String encodedJSON)
This method decrypts the Base64-encoded JSON document using the specified algorithm and cipher
transformation.
|
String |
decryptAsString(String encodedJSON)
This method decrypts the Base64-encoded JSON document using the specified algorithm and cipher
transformation.
|
protected String |
encodeJSON(byte[] encrypted,
byte[] initVector) |
String |
encrypt(byte[] bytes)
This method encrypts an array of bytes.
|
String |
encrypt(String value)
This is a convenience method that takes a String argument, encodes it as Base64, then calls
encrypt(byte[]).
|
String |
encrypt(String transform,
byte[] bytes)
This method encrypts an array of bytes.
|
String |
encrypt(String transform,
String value)
This is a convenience method that takes a String argument, encodes it as Base64, then calls
encrypt(byte[]).
|
static OSymmetricKey |
fromConfig(OSymmetricKeyConfig keyConfig)
Creates an OSymmetricKey from an OSymmetricKeyConfig interface.
|
static OSymmetricKey |
fromFile(String algorithm,
String path)
Creates an OSymmetricKey from a file containing a Base64 key.
|
static OSymmetricKey |
fromKeystore(InputStream is,
String password,
String keyAlias,
String keyPassword)
Creates an OSymmetricKey from a Java "JCEKS" KeyStore.
|
static OSymmetricKey |
fromKeystore(String path,
String password,
String keyAlias,
String keyPassword)
Creates an OSymmetricKey from a Java "JCEKS" KeyStore.
|
static OSymmetricKey |
fromStream(String algorithm,
InputStream is)
Creates an OSymmetricKey from an InputStream containing a Base64 key.
|
static OSymmetricKey |
fromString(String algorithm,
String base64Key)
Creates an OSymmetricKey from a Base64 key.
|
String |
getBase64Key()
Returns the internal SecretKey as a Base64 String.
|
String |
getDefaultCipherTransform(String transform) |
int |
getIteration(int iteration) |
String |
getKeyAlgorithm(String algorithm) |
int |
getKeySize(int bits) |
int |
getSaltLength(int length) |
String |
getSeedAlgorithm(String algorithm) |
String |
getSeedPhrase(String phrase) |
void |
saveToKeystore(OutputStream os,
String ksPasswd,
String keyAlias,
String keyPasswd)
Saves the internal SecretKey as a KeyStore.
|
void |
saveToStream(OutputStream os)
Saves the internal SecretKey to the specified OutputStream as a Base64 String.
|
protected static String |
separateAlgorithm(String cipherTransform)
Returns the secret key algorithm portion of the cipher transformation.
|
OSymmetricKey |
setDefaultCipherTransform(String transform) |
OSymmetricKey |
setIteration(int iteration) |
OSymmetricKey |
setKeyAlgorithm(String algorithm) |
OSymmetricKey |
setKeySize(int bits) |
OSymmetricKey |
setSaltLength(int length) |
OSymmetricKey |
setSeedAlgorithm(String algorithm) |
OSymmetricKey |
setSeedPhrase(String phrase) |
public OSymmetricKey()
public OSymmetricKey(String secretKeyAlgorithm, String cipherTransform, int keySize)
public OSymmetricKey(SecretKey secretKey) throws OSecurityException
OSecurityException
public OSymmetricKey(String algorithm, String base64Key) throws OSecurityException
OSecurityException
public int getIteration(int iteration)
public int getKeySize(int bits)
public int getSaltLength(int length)
public OSymmetricKey setDefaultCipherTransform(String transform)
public OSymmetricKey setIteration(int iteration)
public OSymmetricKey setKeyAlgorithm(String algorithm)
public OSymmetricKey setKeySize(int bits)
public OSymmetricKey setSaltLength(int length)
public OSymmetricKey setSeedAlgorithm(String algorithm)
public OSymmetricKey setSeedPhrase(String phrase)
protected void create()
protected static String separateAlgorithm(String cipherTransform)
public static OSymmetricKey fromConfig(OSymmetricKeyConfig keyConfig)
public static OSymmetricKey fromString(String algorithm, String base64Key)
public static OSymmetricKey fromFile(String algorithm, String path)
public static OSymmetricKey fromStream(String algorithm, InputStream is)
public static OSymmetricKey fromKeystore(String path, String password, String keyAlias, String keyPassword)
path
- The location of the KeyStore file.password
- The password for the KeyStore. May be null.keyAlias
- The alias name of the key to be used from the KeyStore. Required.keyPassword
- The password of the key represented by keyAlias. May be null.public static OSymmetricKey fromKeystore(InputStream is, String password, String keyAlias, String keyPassword)
is
- The InputStream used to load the KeyStore.password
- The password for the KeyStore. May be null.keyAlias
- The alias name of the key to be used from the KeyStore. Required.keyPassword
- The password of the key represented by keyAlias. May be null.public String getBase64Key()
protected static String convertToBase64(byte[] bytes)
protected static byte[] convertFromBase64(String base64)
public String encrypt(String value)
value
- The String to be encoded to Base64 then encrypted.public String encrypt(String transform, String value)
transform
- The cipher transformation to use.value
- The String to be encoded to Base64 then encrypted.public String encrypt(byte[] bytes)
bytes
- The array of bytes to be encrypted.public String encrypt(String transform, byte[] bytes)
transform
- The cipher transformation to use.bytes
- The array of bytes to be encrypted.protected String encodeJSON(byte[] encrypted, byte[] initVector)
public String decryptAsString(String encodedJSON)
encodedJSON
- The Base64-encoded JSON document.public byte[] decrypt(String encodedJSON)
encodedJSON
- The Base64-encoded JSON document.public void saveToStream(OutputStream os)
public void saveToKeystore(OutputStream os, String ksPasswd, String keyAlias, String keyPasswd)
Copyright © 2009–2020 OrientDB. All rights reserved.