public class SecretBytes extends Object implements Serializable
Secret to be used for efficient storage of byte[]. The serialized form will embed the
salt and padding so no two invocations of getEncryptedData() will return the same result, but all will
decrypt to the same getPlainData(). XStream serialization and Stapler form-binding will assume that
the toString() representation is used (i.e. the Base64 encoded secret bytes wrapped with {
and }. If the string representation fails to decrypt (and is not wrapped| Modifier and Type | Class and Description |
|---|---|
static class |
SecretBytes.ConverterImpl
Our XStream converter.
|
static class |
SecretBytes.StaplerConverterImpl |
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
ENCRYPTED_VALUE_PATTERN
Pattern matching a possible output of
toString(). |
| Modifier and Type | Method and Description |
|---|---|
static SecretBytes |
decrypt(byte[] data)
Reverse operation of
getEncryptedData(). |
boolean |
equals(Object o) |
static SecretBytes |
fromBytes(byte[] data)
Attempts to treat the given bytes first as a cipher encrypted bytes, and if it doesn't work,
treat the given bytes as the unencrypted secret value.
|
static SecretBytes |
fromString(String data)
Attempts to treat the given bytes first as a cipher text, and if it doesn't work,
treat the given string as the unencrypted BASE-64 encoded byte array.
|
byte[] |
getEncryptedData()
Returns the encrypted data.
|
byte[] |
getPlainData()
Returns the raw unencrypted data.
|
static byte[] |
getPlainData(SecretBytes s)
Works just like
getPlainData() but avoids NPE when the secret is null. |
int |
hashCode() |
static boolean |
isSecretBytes(String data)
check if the given String is a SecretBytes text by attempting to decrypt it
|
String |
toString() |
static String |
toString(SecretBytes s)
Works just like
toString() but avoids NPE when the secret is null. |
@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public static final Pattern ENCRYPTED_VALUE_PATTERN
toString().
Basically, any Base64-encoded value.
You must then call decrypt(byte[]) to eliminate false positives.@NonNull public byte[] getPlainData()
byte[] after
use.@NonNull public byte[] getEncryptedData()
@CheckForNull public static SecretBytes decrypt(byte[] data)
getEncryptedData(). Returns null
if the given cipher text was invalid.data - the bytes to decrypt.null if the data was not originally encrypted.@NonNull
public static byte[] getPlainData(@CheckForNull
SecretBytes s)
getPlainData() but avoids NPE when the secret is null.
To be consistent with fromBytes(byte[]), this method doesn't distinguish
empty password and null password.s - the secret bytes.public static SecretBytes fromBytes(byte[] data)
Useful for recovering a value from a form field.
If the supplied bytes are known to be unencrypted then the caller is responsible for zeroing out the supplied
byte[] afterwards.
data - the data to wrap or decrypt.@NonNull public static SecretBytes fromString(String data)
Useful for recovering a value from a form field. Note: the caller is responsible for evicting the data from memory in the event that the data is the unencrypted BASE-64 encoded plain data.
data - the string representation to decrypt.public static boolean isSecretBytes(String data)
data - the string to checkpublic static String toString(SecretBytes s)
toString() but avoids NPE when the secret is null.
To be consistent with fromString(String), this method doesn't distinguish
empty password and null password.s - the secret bytes.Copyright © 2016–2017. All rights reserved.