public class KeyInfo
extends java.lang.Object
The KeyInfo is always included in the Capsule when used to encrypt data, so it has
binary-effective packed representation, pack(), which can be used as a hashtag in the
keyring, for example, wrapping it in the Bytes instance make possible
to use it as a Map key and effectively find matching keys.
With symmetric keys special care should be taken to have a correct tag value, as it is
not automatically generated, unlike with RSA keys, where it is 5 first bytes of Sha256() of the
packed public key, which is almost always enough to identify it.
For password-generated keys all necessary information is kept to recreate key by the password
which could be done easily with derivePassword(String).
Created by sergeych on 19.12.16.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
KeyInfo.Algorythm |
|
static class |
KeyInfo.PRF |
Pseudo-random function to use with PBKDF2 to generate key from the password.
|
| Constructor | Description |
|---|---|
KeyInfo(byte[] packedInfo) |
|
KeyInfo(KeyInfo.Algorythm algorythm,
byte[] tag) |
Construct info for the algorythm with fixed key length, e.g.
|
KeyInfo(KeyInfo.Algorythm algorythm,
byte[] tag,
int keyLength) |
|
KeyInfo(KeyInfo.PRF PRF,
int rounds,
byte[] salt,
byte[] tag) |
Construct PBKRF-based password key information.
|
| Modifier and Type | Method | Description |
|---|---|---|
SymmetricKey |
derivePassword(java.lang.String password) |
|
KeyInfo.Algorythm |
getAlgorythm() |
|
java.lang.String |
getBase64Tag() |
|
int |
getKeyLength() |
|
KeyInfo.PRF |
getPRF() |
|
int |
getRounds() |
|
byte[] |
getSalt() |
|
byte[] |
getTag() |
|
boolean |
isPassword() |
|
boolean |
matchTag(KeyInfo keyInfo) |
Return true if other key's tag is same or somehow match this key tag.
|
boolean |
matchType(AbstractKey otherKey) |
See
matchType(KeyInfo) for details. |
boolean |
matchType(KeyInfo otherInfo) |
Check that this key CAN DECRYPT other key.
|
byte[] |
pack() |
|
void |
setTag(byte[] tag) |
|
java.lang.String |
toString() |
|
AbstractKey |
unpackKey(byte[] data) |
public KeyInfo(KeyInfo.Algorythm algorythm, byte[] tag, int keyLength)
public KeyInfo(KeyInfo.Algorythm algorythm, byte[] tag)
KeyInfo.Algorythm.AES256.algorythm - should be one with fixed key lengthtag - optional tag or nullpublic KeyInfo(KeyInfo.PRF PRF, int rounds, byte[] salt, byte[] tag)
PRF - hashing method PRF used in key derivation, see KeyInfo.PRF.rounds - salt - tag - public KeyInfo(byte[] packedInfo)
throws java.io.IOException
java.io.IOExceptionpublic byte[] getSalt()
public boolean matchType(KeyInfo otherInfo)
otherInfo - other key's infopublic boolean matchType(AbstractKey otherKey)
matchType(KeyInfo) for details.otherKey - public boolean matchTag(KeyInfo keyInfo)
keyInfo - other key infopublic void setTag(byte[] tag)
public java.lang.String getBase64Tag()
public boolean isPassword()
public byte[] getTag()
public int getRounds()
public KeyInfo.Algorythm getAlgorythm()
public KeyInfo.PRF getPRF()
public int getKeyLength()
public byte[] pack()
public SymmetricKey derivePassword(java.lang.String password)
public AbstractKey unpackKey(byte[] data) throws EncryptionError
EncryptionErrorpublic java.lang.String toString()
toString in class java.lang.Object