KeyMatcher, net.sergeych.tools.BindableAbstractAsymmetricKey, PrivateKey, PublicKey, SymmetricKeypublic abstract class AbstractKey extends java.lang.Object implements net.sergeych.tools.Bindable, KeyMatcher
UnsupportedOperationException - this is a valid behaviour for the function that the key is not able to perform.
Well, there could be keys that do nothing too. Just for ;)
Created by sergeych on 17.12.16.
| Modifier and Type | Field | Description |
|---|---|---|
static int |
FINGERPRINT_SHA256 |
|
static int |
FINGERPRINT_SHA384 |
|
protected KeyInfo |
keyInfo |
|
static int |
TYPE_PRIVATE |
|
static int |
TYPE_PRIVATE_PASSWORD |
|
static int |
TYPE_PRIVATE_PASSWORD_V2 |
|
static int |
TYPE_PUBLIC |
| Constructor | Description |
|---|---|
AbstractKey() |
| Modifier and Type | Method | Description |
|---|---|---|
KeyAddress |
address(boolean useSha3_384,
int keyMark) |
Generate address for the key, see
KeyAddress for more. |
Capsule.KeySource |
asKeySource() |
Generate single-key
Capsule.KeySource for this key. |
boolean |
canSign() |
If it is an instance of the private key, it will return true, then
getPublicKey() must return valid
key. |
byte[] |
createAnonymousId() |
Create a random (e.g.
|
byte[] |
decrypt(byte[] plain) |
|
byte[] |
encrypt(byte[] plain) |
|
byte[] |
fingerprint() |
The fingerprint of the key is a uniqie sequence of bytes that matches the key without compromising it.
|
static AbstractKey |
fromBinder(net.sergeych.tools.Binder binder) |
Deserialize some key instance from the binder using KeyInfo.
|
KeyAddress |
getLongAddress() |
|
AbstractKey |
getPublicKey() |
Return valid public key, for example self, or raise the exception.
|
KeyAddress |
getShortAddress() |
|
KeyInfo |
info() |
|
boolean |
isMatchingKey(AbstractKey key) |
|
boolean |
isMatchingKeyAddress(KeyAddress other) |
|
boolean |
isPrivate() |
|
boolean |
isPublic() |
|
boolean |
matchAnonymousId(@org.checkerframework.checker.nullness.qual.NonNull byte[] packedId) |
Check that the packed anonymousId matches current key.
|
boolean |
matchTag(AbstractKey other) |
|
boolean |
matchType(AbstractKey other) |
|
byte[] |
pack() |
|
byte[] |
packedInfo() |
|
java.lang.String |
packToBase64String() |
|
void |
setTag(byte[] tag) |
|
void |
setTag(java.lang.String tag) |
|
byte[] |
sign(byte[] input,
HashType hashType) |
|
byte[] |
sign(java.io.InputStream input,
HashType hashType) |
|
net.sergeych.tools.Binder |
toBinder() |
Serialize key to the
Binder. |
java.lang.String |
toString() |
|
void |
unpack(byte[] bytes) |
|
Digest |
updateDigestWithKeyComponents(Digest digest) |
Arbitrary fingerprint calculation.
|
<T> T |
updateFrom(net.sergeych.tools.Binder source) |
|
boolean |
verify(byte[] input,
byte[] signature,
HashType hashType) |
|
boolean |
verify(java.io.InputStream input,
byte[] signature,
HashType hashType) |
|
boolean |
verify(java.lang.String input,
byte[] signature,
HashType hashType) |
public static final int FINGERPRINT_SHA256
public static final int FINGERPRINT_SHA384
public static final int TYPE_PRIVATE
public static final int TYPE_PUBLIC
public static final int TYPE_PRIVATE_PASSWORD
public static final int TYPE_PRIVATE_PASSWORD_V2
protected KeyInfo keyInfo
public byte[] encrypt(byte[] plain)
throws EncryptionError
EncryptionErrorpublic byte[] decrypt(byte[] plain)
throws EncryptionError
EncryptionErrorpublic byte[] sign(java.io.InputStream input,
HashType hashType)
throws EncryptionError,
java.io.IOException
EncryptionErrorjava.io.IOExceptionpublic byte[] sign(byte[] input,
HashType hashType)
throws EncryptionError
EncryptionErrorpublic boolean verify(java.io.InputStream input,
byte[] signature,
HashType hashType)
throws EncryptionError,
java.io.IOException
EncryptionErrorjava.io.IOExceptionpublic boolean verify(byte[] input,
byte[] signature,
HashType hashType)
throws EncryptionError
EncryptionErrorpublic boolean verify(java.lang.String input,
byte[] signature,
HashType hashType)
throws EncryptionError
EncryptionErrorpublic KeyInfo info()
public byte[] packedInfo()
public byte[] pack()
public java.lang.String packToBase64String()
public void unpack(byte[] bytes)
throws EncryptionError
EncryptionErrorpublic boolean canSign()
getPublicKey() must return valid
key.public boolean isPublic()
public boolean isPrivate()
public AbstractKey getPublicKey()
isPublic() or throws an exception.public final net.sergeych.tools.Binder toBinder()
Binder. Due to the multiplatform nature of attesta items, especially keys that are
often part of the Capsule, it is not possible to use default java serialization mechanics. Instead, we
serialize objects to Binders that can be effectively transmitted over the network and reconstructed on the any
platform.
Note that derived classes usually do not override it, instead, they should properly initialize keyInfo
and provide pack() and unpack(byte[]) methods, that are widely used across the system. for that
reason we make this method final as for now. If you think you know the case when it is necessary to override it,
contact developers.
See fromBinder(Binder) for deserialization.
toBinder in interface net.sergeych.tools.Bindablepublic final <T> T updateFrom(net.sergeych.tools.Binder source)
throws java.io.IOException
updateFrom in interface net.sergeych.tools.Bindablejava.io.IOExceptionpublic static AbstractKey fromBinder(net.sergeych.tools.Binder binder) throws java.io.IOException, EncryptionError
toBinder(). Serialized data are
in binary form and are bit-effective, when using with Boss encoders (the default for
Attesta).binder - from where to restore.java.io.IOExceptionEncryptionErrorpublic boolean matchType(AbstractKey other)
public boolean matchTag(AbstractKey other)
public void setTag(java.lang.String tag)
public void setTag(byte[] tag)
public java.lang.String toString()
toString in class java.lang.Objectpublic Capsule.KeySource asKeySource()
Capsule.KeySource for this key. Useful to unpack a capsule with a given key and when
you need to use one key in different roles (e.g. decsrypt and check signature).public byte[] fingerprint()
Therefore, the private key fingerprint is its public key fingerprint. The public key fingerprint is calculated
using some hash over it's parameters, see PublicKey.fingerprint()
public Digest updateDigestWithKeyComponents(Digest digest)
Create any digest you need and call this method to update it with a ket data.
This can and should be used to obtain higher-order composite fingerprints for high security setups.
public byte[] createAnonymousId()
Anonymous ID size is 64 bytes: first are 32 random bytes, last are HMAC(key, sha256) of these random bytes.
The most important thing about anonymous ids is that every time this call generates new id for the same key, providing anonymous but exact identification of a key.
To check that the key matches some anonymousId, use matchAnonymousId(byte[]).
Therefore, the private key fingerprint is its public key fingerprint. The public key fingerprint is calculated
using some hash over it's parameters, see PublicKey.fingerprint()
public boolean matchAnonymousId(@org.checkerframework.checker.nullness.qual.NonNull byte[] packedId)
throws java.io.IOException
createAnonymousId() to get a random anonymous
id for this key.packedId - java.io.IOExceptionpublic KeyAddress address(boolean useSha3_384, int keyMark)
KeyAddress for more.useSha3_384 - use SHA3-384 for hash, otherwise SHA3-256keyMark - some data code in 0..15 range inclusivepublic final KeyAddress getShortAddress()
public final KeyAddress getLongAddress()
public boolean isMatchingKey(AbstractKey key)
isMatchingKey in interface KeyMatcherpublic final boolean isMatchingKeyAddress(KeyAddress other)
isMatchingKeyAddress in interface KeyMatcher