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 Details

    • ee

      AnB crypto wrapper class provide implementation of general crypto and channel methods
    • me

      protected AnBx_Agent me
      the identity of the agent
    • ident_ks

      protected final Crypto_KeyStoreType ident_ks
      the crypto store type
  • Constructor Details

  • Method Details

    • getInfo

      public static void getInfo()
      Prints information about the cryptographic engine including supported algorithms
      See Also:
    • Setup

      public void Setup(Crypto_KeyStoreSettings_Map kssd)
      Setup a AnB_Crypto_Wrapper for a specified key store setting map
      Parameters:
      kssd - the specified key store setting map
    • Setup

      public void Setup(Crypto_KeyStoreSettings_Map kssd, Crypto_Config config)
      Setup 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:
    • 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:
    • 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
    • setMyIdentity

      protected void setMyIdentity()
      Set the identity of the current agent
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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
    • 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:
    • 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:
    • 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:
    • 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:
    • xor

      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:
    • 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