Package esmska.data

Class Keyring


  • public class Keyring
    extends java.lang.Object
    Storage for logins and passwords to gateways. Also offers password encryption and decryption.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addActionListener​(java.awt.event.ActionListener actionListener)  
      void clearKeys()
      Clear all gateway names and corresponding keys from the keyring.
      static java.lang.String decrypt​(java.lang.String input)
      Decrypt input string.
      static java.lang.String encrypt​(java.lang.String input)
      Encrypt input string.
      java.util.Set<java.lang.String> getGatewayNames()
      Get set of all gateway names, which are in the keyring.
      static Keyring getInstance()
      Get shared instance
      Tuple<java.lang.String,​java.lang.String> getKey​(java.lang.String gatewayName)
      Get key for chosen gateway.
      void putKey​(java.lang.String gatewayName, Tuple<java.lang.String,​java.lang.String> key)
      Put key for chosen gateway.
      void putKeys​(java.util.Map<java.lang.String,​Tuple<java.lang.String,​java.lang.String>> keys)
      Put keys for more gateways.
      void removeActionListener​(java.awt.event.ActionListener actionListener)  
      void removeKey​(java.lang.String gatewayName)
      Remove chosen gateway from the keyring.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ACTION_ADD_KEY

        public static final int ACTION_ADD_KEY
        new key added or existing changed
        See Also:
        Constant Field Values
      • ACTION_REMOVE_KEY

        public static final int ACTION_REMOVE_KEY
        existing key removed
        See Also:
        Constant Field Values
      • ACTION_CLEAR_KEYS

        public static final int ACTION_CLEAR_KEYS
        all keys removed
        See Also:
        Constant Field Values
    • Method Detail

      • addActionListener

        public void addActionListener​(java.awt.event.ActionListener actionListener)
      • removeActionListener

        public void removeActionListener​(java.awt.event.ActionListener actionListener)
      • getInstance

        public static Keyring getInstance()
        Get shared instance
      • getKey

        public Tuple<java.lang.String,​java.lang.String> getKey​(java.lang.String gatewayName)
        Get key for chosen gateway.
        Parameters:
        gatewayName - Name of the gateway.
        Returns:
        tuple in the form [login, password] if key for this gateway exists. Null otherwise.
      • putKey

        public void putKey​(java.lang.String gatewayName,
                           Tuple<java.lang.String,​java.lang.String> key)
        Put key for chosen gateway. If a key for this gateway already exists, overwrite previous one.
        Parameters:
        gatewayName - Name of the gateway.
        key - tuple in the form [login, password].
        Throws:
        java.lang.IllegalArgumentException - If gatewayName or key is null.
      • putKeys

        public void putKeys​(java.util.Map<java.lang.String,​Tuple<java.lang.String,​java.lang.String>> keys)
        Put keys for more gateways. If a key for particular gateway already exists, overwrite previous one.
        Parameters:
        keys - Map in the form [gatewayName, Key], where Key is in the form [login, password].
        Throws:
        java.lang.IllegalArgumentException - If some gatewayName or some key is null.
      • removeKey

        public void removeKey​(java.lang.String gatewayName)
        Remove chosen gateway from the keyring.
        Parameters:
        gatewayName - Name of the gateway.
      • getGatewayNames

        public java.util.Set<java.lang.String> getGatewayNames()
        Get set of all gateway names, which are in the keyring.
        Returns:
        Unmodifiable set of all gateway names, which are in the keyring.
      • clearKeys

        public void clearKeys()
        Clear all gateway names and corresponding keys from the keyring. The keyring will be empty after this.
      • encrypt

        public static java.lang.String encrypt​(java.lang.String input)
        Encrypt input string. The string is encrypted using XOR encryption with internal passphrase, doubled and the result is encoded using the Base64 encoding.
        Parameters:
        input - Input string. Null is transformed to empty string.
        Returns:
        Encrypted string
      • decrypt

        public static java.lang.String decrypt​(java.lang.String input)
        Decrypt input string. The input string is decoded using the Base64 encoding, halved, and the result is decrypted using XOR encryption with internal passphrase.
        Parameters:
        input - Input string. The input must originate from the encrypt() function. Null is transformed to empty string.
        Returns:
        Decrypted string.