Package anbxj

# Class AnB_Crypto_Wrapper

java.lang.Object
anbxj.AnB_Crypto_Wrapper

Direct Known Subclasses:
  `AnB_Session`

public class AnB_Crypto_Wrapper extends Object
Cryptographic API: implements a class supporting cryptographic operations (a wrapper for the cryptographic engine)

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Crypto_EncryptionEngine`
  `ee`
  the cryptographic engine
  `protected final Crypto_KeyStoreType`
  `ident_ks`
  the crypto store type
  `protected final AnBx_Agent`
  `me`
  the identity of the agent

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AnB_Crypto_Wrapper(Crypto_EncryptionEngine ee)`
  Create a AnB_Crypto_Wrapper for a specified cryptographic engine
  `AnB_Crypto_Wrapper(Crypto_KeyStoreSettings_Map kssd)`
  Create a AnB_Crypto_Wrapper for a specified key store setting map
  `AnB_Crypto_Wrapper(Crypto_KeyStoreSettings_Map kssd, Crypto_Config config)`
  Create a AnB_Crypto_Wrapper for a specified key store setting map and cryptographic configuration
  `AnB_Crypto_Wrapper(String myAlias, Crypto_Config config)`
  Create a AnB_Crypto_Wrapper for a specified key store setting map and cryptographic configuration
  `AnB_Crypto_Wrapper(String myAlias, Crypto_EncryptionEngine ee)`
  Create a AnB_Crypto_Wrapper for a specified cryptographic engine

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `aliasExists(String alias)`
  Check is an agent's alias is stored in the key stores accessible to the cryptographic engine
  `boolean`
  `checkHmac(Object object, Crypto_ByteArray hmac, SecretKey sk)`
  Check a hmac value of a given object computed with the default hashing algorithm and a specified secret key
  `Object`
  `decrypt(Crypto_SealedPair sc)`
  Decrypts a Crypto_SealedPair with the private key from the default key store associated to current agent
  `Object`
  `decrypt(Crypto_SealedPair sc, Crypto_KeyPair kp)`
  Decrypts a Crypto_SealedPair with the private key from a specified key pair
  `Object`
  `decrypt(Crypto_SealedPair sc, Crypto_KeyStoreType pk)`
  Decrypts a Crypto_SealedPair with the private key from a specified key store associated to current agent
  `Object`
  `decrypt(SealedObject so, SecretKey symmetricKey)`
  Decrypts a SealedObject with a specified symmetric key
  `Crypto_SealedPair`
  `encrypt(Object object, Crypto_KeyPair kp)`
  Encrypts an object with the public key of a specified key pair
  `Crypto_SealedPair`
  `encrypt(Object object, String alias)`
  Encrypts an object with a public key retrieved from the default key store associated to an user identified by an alias
  `Crypto_SealedPair`
  `encrypt(Object object, String alias, Crypto_KeyStoreType pk)`
  Encrypts an object with a public key retrieved from a specified key store associated to an user identified by an alias
  `Crypto_SealedPair`
  `encrypt(Object object, PublicKey publicKey)`
  Encrypts an object with a specified public key
  `SealedObject`
  `encrypt(Object object, SecretKey symmetricKey)`
  Encrypts an object with a specified symmetric key
  `SecretKey`
  `getHmacKey()`
  Generates a HMAC secret key
  `static void`
  `getInfo()`
  Prints information about the cryptographic engine including supported algorithms
  `KeyPair`
  `getKeyEx_KeyPair()`
  Generates a key exchange key pair for the default key agreement algorithm
  `PublicKey`
  `getKeyEx_PublicKey(KeyPair keyPair)`
  Retrieves the public key from a specified key exchange key pair
  `SecretKey`
  `getKeyEx_SecretKey(PublicKey publicKey, KeyPair keyPair)`
  Retrieves the secret key from a specified key exchange key pair and associated public key
  `Crypto_KeyPair`
  `getKeyPair()`
  Generates a key pair for the default public key algorithm
  `Crypto_KeyStoreSettings_Map`
  `getKeyStoreSettings_Map()`
  Retrieve the default Crypto_KeyStoreSettings_Map for the current cryptographic engine
  `protected AnBx_Agent`
  `getMyIdentity()`
  Retrieve the identity of the current agent
  `String`
  `getName()`
  Returns the agent name associated with this for the current AnB_Crypto_Wrapper
  `Crypto_ByteArray`
  `getNonce()`
  Generates a fresh nonce
  `PublicKey`
  `getPublicKey(Crypto_KeyPair pair)`
  Retrieves the public key from a specified key pair
  `PublicKey`
  `getPublicKey(String alias, Crypto_KeyStoreType kst)`
  Retrieve a public key associated to an agent's alias for a specified Crypto_KeyStoreType
  `protected Certificate`
  `getRemoteCertificate(String alias, Crypto_KeyStoreType kst)`
  Retrieve the certificate associated to an agent's alias for a specified Crypto_KeyStoreType
  `protected Map<Crypto_KeyStoreType,Certificate>`
  `getRemoteCertificates(String alias)`
  Retrieve the certificates associated to an agent's alias
  `Crypto_ByteArray`
  `getSeqNumber()`
  Generates a sequence number
  `SecretKey`
  `getSymmetricKey()`
  Generates a symmetric key
  `SecretKey`
  `getSymmetricKey(Crypto_KeyMode km)`
  Generates a symmetric key specifying a key mode
  `SecretKey`
  `getSymmetricKeyPBE(String password, String salt)`
  Generates a symmetric key for Password Based Encryption (PBE)
  `Instant`
  `getTimeStamp()`
  Generates a time stamp
  `static boolean`
  `isLoggingExecTimeEnabled()`
  Checks whether logging is currently enabled.
  `Crypto_ByteArray`
  `makeDigest(Object object)`
  Computes the hash of a given object with the default hashing algorithm
  `Crypto_ByteArray`
  `makeHmac(Object object, SecretKey sk)`
  Computes the hmac of a given object with the default hashing algorithm and a specified secret key
  `static Object`
  `readObject(String filename)`
  Writes a serialised object from the file system
  `protected Object`
  `Receive(Channel_Abstraction c)`
  Receive an object from a channel
  `protected AnBx_Agent`
  `Receive_RemoteId(Channel_Abstraction c)`
  Receive the identity of an agent from a channel
  `protected void`
  `Send(Object obj, Channel_Abstraction c)`
  Send an object over a channel
  `protected void`
  `Send_Id(AnBx_Agent id, Channel_Abstraction c)`
  Send the identity of an agent over a channel
  `static void`
  `setLoggingExecTimeEnabled(boolean enabled)`
  Sets the logging state for performance measurements.
  `SignedObject`
  `sign(Object object)`
  Signs an object with the private key of the current agent retrieved from the default key store
  `SignedObject`
  `sign(Object object, Crypto_KeyPair kp)`
  Signs an object with a private key retrieved from the specified key pair
  `SignedObject`
  `sign(Object object, Crypto_KeyStoreType sk)`
  Signs an object with the private key of the current agent retrieved from a specified key store
  `Object`
  `verify(SignedObject so, String alias)`
  Verifies a SignedObject with a private key retrieved from the default key store associated to an agent identified by an alias
  `Object`
  `verify(SignedObject so, String alias, Crypto_KeyStoreType sk)`
  Verifies a SignedObject with a private key retrieved from a specified key store associated to an agent identified by an alias
  `Object`
  `verify(SignedObject so, PublicKey pk)`
  Verifies a SignedObject with a specified public key
  `static void`
  `writeObject(Object object, String filename)`
  Writes a serialised object to the file system
  `Crypto_ByteArray`
  `xor(Crypto_ByteArray x1, Crypto_ByteArray x2)`
  Computes the xor of two Crypto_ByteArrays

  ### Methods inherited from class java.lang.Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ee

    protected final Crypto_EncryptionEngine ee
    the cryptographic engine

  - ### me

    protected final AnBx_Agent me
    the identity of the agent

  - ### ident_ks

    protected final Crypto_KeyStoreType ident_ks
    the crypto store type

- ## Constructor Details

  - ### AnB_Crypto_Wrapper

    public AnB_Crypto_Wrapper(String myAlias, Crypto_EncryptionEngine ee)
    Create a AnB_Crypto_Wrapper for a specified cryptographic engine
    Parameters:
      `myAlias` - Alias of the principal
      `ee` - the specified cryptographic engine
    See Also:
      - `AnB_Crypto_Wrapper`
      - `Crypto_EncryptionEngine`

  - ### AnB_Crypto_Wrapper

    public AnB_Crypto_Wrapper(Crypto_EncryptionEngine ee)
    Create a AnB_Crypto_Wrapper for a specified cryptographic engine
    Parameters:
      `ee` - the specified cryptographic engine
    See Also:
      - `AnB_Crypto_Wrapper`
      - `Crypto_EncryptionEngine`

  - ### AnB_Crypto_Wrapper

    public AnB_Crypto_Wrapper(Crypto_KeyStoreSettings_Map kssd)
    Create a AnB_Crypto_Wrapper for a specified key store setting map
    Parameters:
      `kssd` - the specified key store setting map
    See Also:
      - `Crypto_KeyStoreSettings_Map`

  - ### AnB_Crypto_Wrapper

    public AnB_Crypto_Wrapper(Crypto_KeyStoreSettings_Map kssd, Crypto_Config config)
    Create a AnB_Crypto_Wrapper for a specified key store setting map and cryptographic configuration
    Parameters:
      `kssd` - the specified key store setting map
      `config` - the specified cryptographic configuration
    See Also:
      - `Crypto_KeyStoreSettings_Map`
      - `Crypto_Config`

  - ### AnB_Crypto_Wrapper

    public AnB_Crypto_Wrapper(String myAlias, Crypto_Config config)
    Create a AnB_Crypto_Wrapper for a specified key store setting map and cryptographic configuration
    Parameters:
      `myAlias` - Alias of the principal
      `config` - the specified cryptographic configuration
    See Also:
      - `Crypto_KeyStoreSettings_Map`
      - `Crypto_Config`

- ## Method Details

  - ### setLoggingExecTimeEnabled

    public static void setLoggingExecTimeEnabled(boolean enabled)
    Sets the logging state for performance measurements.
    Parameters:
      `enabled` - `true` to enable logging, `false` to disable logging.

  - ### isLoggingExecTimeEnabled

    public static boolean isLoggingExecTimeEnabled()
    Checks whether logging is currently enabled.
    Returns:
      `true` if logging is enabled, `false` otherwise.

  - ### getInfo

    public static void getInfo()
    Prints information about the cryptographic engine including supported algorithms
    See Also:
      - `Crypto_EncryptionEngine`

  - ### getKeyStoreSettings_Map

    public Crypto_KeyStoreSettings_Map getKeyStoreSettings_Map()
    Retrieve the default Crypto_KeyStoreSettings_Map for the current cryptographic engine
    Returns:
      the Crypto_KeyStoreSettings_Map
    See Also:
      - `Crypto_KeyStoreSettings_Map`

  - ### getName

    public String getName()
    Returns the agent name associated with this for the current AnB_Crypto_Wrapper
    Returns:
      the agent's name

  - ### aliasExists

    public boolean aliasExists(String alias)
    Check is an agent's alias is stored in the key stores accessible to the cryptographic engine
    Parameters:
      `alias` - the agent's alias
    Returns:
      true if the agent's alias exists

  - ### getPublicKey

    public PublicKey getPublicKey(String alias, Crypto_KeyStoreType kst)
    Retrieve a public key associated to an agent's alias for a specified Crypto_KeyStoreType
    Parameters:
      `alias` - the agent's alias
      `kst` - the crypto key store type
    Returns:
      the public key

  - ### getRemoteCertificate

    protected Certificate getRemoteCertificate(String alias, Crypto_KeyStoreType kst)
    Retrieve the certificate associated to an agent's alias for a specified Crypto_KeyStoreType
    Parameters:
      `alias` - the agent's alias
      `kst` - the crypto key store type
    Returns:
      the certificate

  - ### getRemoteCertificates

    protected Map<Crypto_KeyStoreType,Certificate> getRemoteCertificates(String alias)
    Retrieve the certificates associated to an agent's alias
    Parameters:
      `alias` - the agent's alias
    Returns:
      the certificates

  - ### getMyIdentity

    protected AnBx_Agent getMyIdentity()
    Retrieve the identity of the current agent
    Returns:
      the identity

  - ### Send

    protected void Send(Object obj, Channel_Abstraction c)
    Send an object over a channel
    Parameters:
      `obj` - the object
      `c` - the channel abstraction

  - ### Receive

    protected Object Receive(Channel_Abstraction c)
    Receive an object from a channel
    Parameters:
      `c` - the channel abstraction
    Returns:
      the object

  - ### Send_Id

    protected void Send_Id(AnBx_Agent id, Channel_Abstraction c)
    Send the identity of an agent over a channel
    Parameters:
      `id` - the agent id
      `c` - the channel abstraction

  - ### Receive_RemoteId

    protected AnBx_Agent Receive_RemoteId(Channel_Abstraction c)
    Receive the identity of an agent from a channel
    Parameters:
      `c` - the channel abstraction
    Returns:
      the agent identity

  - ### encrypt

    public Crypto_SealedPair encrypt(Object object, String alias)
    Encrypts an object with a public key retrieved from the default key store associated to an user identified by an alias
    Parameters:
      `object` - the object to encrypt
      `alias` - the identifier of the agent
    Returns:
      the encrypted object as Crypto_SealedPair
    See Also:
      - `Crypto_SealedPair`

  - ### encrypt

    public Crypto_SealedPair encrypt(Object object, String alias, Crypto_KeyStoreType pk)
    Encrypts an object with a public key retrieved from a specified key store associated to an user identified by an alias
    Parameters:
      `object` - the object to encrypt
      `alias` - the identifier of the agent
      `pk` - the specified key store
    Returns:
      the encrypted object as Crypto_SealedPair
    See Also:
      - `Crypto_SealedPair`
      - `Crypto_KeyStoreType`

  - ### encrypt

    public Crypto_SealedPair encrypt(Object object, Crypto_KeyPair kp)
    Encrypts an object with the public key of a specified key pair
    Parameters:
      `object` - the object to encrypt
      `kp` - the specified key pair
    Returns:
      the encrypted object as Crypto_SealedPair
    See Also:
      - `Crypto_SealedPair`

  - ### encrypt

    public Crypto_SealedPair encrypt(Object object, PublicKey publicKey)
    Encrypts an object with a specified public key
    Parameters:
      `object` - the object to encrypt
      `publicKey` - the specified public key
    Returns:
      the encrypted object as Crypto_SealedPair
    See Also:
      - `Crypto_SealedPair`

  - ### decrypt

    public Object decrypt(Crypto_SealedPair sc)
    Decrypts a Crypto_SealedPair with the private key from the default key store associated to current agent
    Parameters:
      `sc` - the Crypto_SealedPair to decrypt
    Returns:
      the decrypted object
    See Also:
      - `Crypto_SealedPair`

  - ### decrypt

    public Object decrypt(Crypto_SealedPair sc, Crypto_KeyStoreType pk)
    Decrypts a Crypto_SealedPair with the private key from a specified key store associated to current agent
    Parameters:
      `sc` - the Crypto_SealedPair to decrypt
      `pk` - the specified key store
    Returns:
      the decrypted object
    See Also:
      - `Crypto_SealedPair`
      - `Crypto_KeyStoreType`

  - ### decrypt

    public Object decrypt(Crypto_SealedPair sc, Crypto_KeyPair kp)
    Decrypts a Crypto_SealedPair with the private key from a specified key pair
    Parameters:
      `sc` - the Crypto_SealedPair to decrypt
      `kp` - the specified key pair
    Returns:
      the decrypted object
    See Also:
      - `Crypto_KeyPair`

  - ### encrypt

    public SealedObject encrypt(Object object, SecretKey symmetricKey)
    Encrypts an object with a specified symmetric key
    Parameters:
      `object` - the object to encrypt
      `symmetricKey` - the specified symmetric key
    Returns:
      the encrypted object as SealedObject

  - ### decrypt

    public Object decrypt(SealedObject so, SecretKey symmetricKey)
    Decrypts a SealedObject with a specified symmetric key
    Parameters:
      `so` - the SealedObject to encrypt
      `symmetricKey` - the specified symmetric key
    Returns:
      the encrypted object as SealedObject

  - ### sign

    public SignedObject sign(Object object)
    Signs an object with the private key of the current agent retrieved from the default key store
    Parameters:
      `object` - the object to sign
    Returns:
      the signed object as SignedObject

  - ### sign

    public SignedObject sign(Object object, Crypto_KeyStoreType sk)
    Signs an object with the private key of the current agent retrieved from a specified key store
    Parameters:
      `object` - the object to sign
      `sk` - the specified key store
    Returns:
      the signed object as SignedObject
    See Also:
      - `Crypto_KeyStoreType`

  - ### sign

    public SignedObject sign(Object object, Crypto_KeyPair kp)
    Signs an object with a private key retrieved from the specified key pair
    Parameters:
      `object` - the object to sign
      `kp` - the specified key pair
    Returns:
      the signed object as SignedObject
    See Also:
      - `Crypto_KeyPair`

  - ### verify

    public Object verify(SignedObject so, String alias)
    Verifies a SignedObject with a private key retrieved from the default key store associated to an agent identified by an alias
    Parameters:
      `so` - the SignedObject to verify
      `alias` - the identifier of the agent
    Returns:
      the verified object
    See Also:
      - `Crypto_KeyPair`

  - ### verify

    public Object verify(SignedObject so, String alias, Crypto_KeyStoreType sk)
    Verifies a SignedObject with a private key retrieved from a specified key store associated to an agent identified by an alias
    Parameters:
      `so` - the SignedObject to verify
      `alias` - the identifier of the agent
      `sk` - the specified key store
    Returns:
      the verified object
    See Also:
      - `Crypto_KeyStoreType`

  - ### verify

    public Object verify(SignedObject so, PublicKey pk)
    Verifies a SignedObject with a specified public key
    Parameters:
      `so` - the SignedObject to verify
      `pk` - the specified public key
    Returns:
      the verified object

  - ### getNonce

    public Crypto_ByteArray getNonce()
    Generates a fresh nonce
    Returns:
      the fresh nonce

  - ### getSeqNumber

    public Crypto_ByteArray getSeqNumber()
    Generates a sequence number
    Returns:
      the sequence number

  - ### getSymmetricKey

    public SecretKey getSymmetricKey()
    Generates a symmetric key
    Returns:
      the symmetric key

  - ### getSymmetricKey

    public SecretKey getSymmetricKey(Crypto_KeyMode km)
    Generates a symmetric key specifying a key mode
    Parameters:
      `km` - the key mode for key generation
    Returns:
      the symmetric key

  - ### getHmacKey

    public SecretKey getHmacKey()
    Generates a HMAC secret key
    Returns:
      the HMAC secret key

  - ### getTimeStamp

    public Instant getTimeStamp()
    Generates a time stamp
    Returns:
      the time stamp

  - ### getSymmetricKeyPBE

    public SecretKey getSymmetricKeyPBE(String password, String salt)
    Generates a symmetric key for Password Based Encryption (PBE)
    Parameters:
      `password` - the password
      `salt` - the salting argument
    Returns:
      the symmetric key

  - ### getKeyEx_KeyPair

    public KeyPair getKeyEx_KeyPair()
    Generates a key exchange key pair for the default key agreement algorithm
    Returns:
      the key exchange key pair

  - ### getKeyEx_PublicKey

    public PublicKey getKeyEx_PublicKey(KeyPair keyPair)
    Retrieves the public key from a specified key exchange key pair
    Parameters:
      `keyPair` - the specified key pair
    Returns:
      the key pair

  - ### getKeyEx_SecretKey

    public SecretKey getKeyEx_SecretKey(PublicKey publicKey, KeyPair keyPair)
    Retrieves the secret key from a specified key exchange key pair and associated public key
    Parameters:
      `publicKey` - the associated public key
      `keyPair` - the specified key pair
    Returns:
      the (symmetric) secret key

  - ### getKeyPair

    public Crypto_KeyPair getKeyPair()
    Generates a key pair for the default public key algorithm
    Returns:
      the key pair
    See Also:
      - `Crypto_KeyPair`

  - ### getPublicKey

    public PublicKey getPublicKey(Crypto_KeyPair pair)
    Retrieves the public key from a specified key pair
    Parameters:
      `pair` - the specified key pair
    Returns:
      the public key
    See Also:
      - `Crypto_KeyPair`

  - ### makeDigest

    public Crypto_ByteArray makeDigest(Object object)
    Computes the hash of a given object with the default hashing algorithm
    Parameters:
      `object` - the given object
    Returns:
      the hash value as Crypto_ByteArray

  - ### makeHmac

    public Crypto_ByteArray makeHmac(Object object, SecretKey sk)
    Computes the hmac of a given object with the default hashing algorithm and a specified secret key
    Parameters:
      `object` - the given object
      `sk` - the secret key
    Returns:
      the hmac value as Crypto_ByteArray
    See Also:
      - `Crypto_ByteArray`

  - ### checkHmac

    public boolean checkHmac(Object object, Crypto_ByteArray hmac, SecretKey sk)
    Check a hmac value of a given object computed with the default hashing algorithm and a specified secret key
    Parameters:
      `object` - the given object
      `hmac` - the hmac value
      `sk` - the secret key
    Returns:
      the hmac value as Crypto_ByteArray
    See Also:
      - `Crypto_ByteArray`

  - ### xor

    public Crypto_ByteArray xor(Crypto_ByteArray x1, Crypto_ByteArray x2)
    Computes the xor of two Crypto_ByteArrays
    Parameters:
      `x1` - the first Crypto_ByteArray argument
      `x2` - the second Crypto_ByteArray argument
    Returns:
      the computed xor value
    See Also:
      - `Crypto_ByteArray`

  - ### writeObject

    public static void writeObject(Object object, String filename)
    Writes a serialised object to the file system
    Parameters:
      `object` - the given object
      `filename` - the specified destination file

  - ### readObject

    public static Object readObject(String filename)
    Writes a serialised object from the file system
    Parameters:
      `filename` - the specified source file
    Returns:
      the retrieved object