Package esmska.data
Class Keyring
- java.lang.Object
-
- esmska.data.Keyring
-
public class Keyring extends java.lang.ObjectStorage for logins and passwords to gateways. Also offers password encryption and decryption.
-
-
Field Summary
Fields Modifier and Type Field Description static intACTION_ADD_KEYnew key added or existing changedstatic intACTION_CLEAR_KEYSall keys removedstatic intACTION_REMOVE_KEYexisting key removed
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddActionListener(java.awt.event.ActionListener actionListener)voidclearKeys()Clear all gateway names and corresponding keys from the keyring.static java.lang.Stringdecrypt(java.lang.String input)Decrypt input string.static java.lang.Stringencrypt(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 KeyringgetInstance()Get shared instanceTuple<java.lang.String,java.lang.String>getKey(java.lang.String gatewayName)Get key for chosen gateway.voidputKey(java.lang.String gatewayName, Tuple<java.lang.String,java.lang.String> key)Put key for chosen gateway.voidputKeys(java.util.Map<java.lang.String,Tuple<java.lang.String,java.lang.String>> keys)Put keys for more gateways.voidremoveActionListener(java.awt.event.ActionListener actionListener)voidremoveKey(java.lang.String gatewayName)Remove chosen gateway from the keyring.
-
-
-
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.
-
-