001package org.intellimate.izou.security.storage; 002 003import java.io.Serializable; 004import java.util.HashMap; 005 006/** 007 * The SecureContainer represents a way to store data safely without other addOns having access to it. However the user 008 * does have access to it, theoretically. 009 * <p> 010 * A SecureContainer has to be completly {@link Serializable} as it is stored as an object. It contains a hashmap 011 * that encrypts any key-value pairs before they are added. You can extend this class to pass additional data to be 012 * stored, however there is no guarantee it is stored safely in that case. 013 * </p> 014 */ 015//TODO: @Julian why doesn't it extend IzouModule? 016public class SecureContainer implements Serializable { 017 private HashMap<byte[], byte[]> cryptData; 018 private HashMap<String, String> clearTextData; 019 020 /** 021 * Creates a new secure container 022 */ 023 public SecureContainer() { 024 cryptData = new HashMap<>(); 025 clearTextData = new HashMap<>(); 026 } 027 028 /** 029 * Encrypts and adds {@code key} and {@code value} to the stored data map 030 * 031 * @param key the key to save 032 * @param value the value to save the key with 033 */ 034 public void securePut(String key, String value) { 035 clearTextData.put(key, value); 036 } 037 038 /** 039 * Retrieves and decrypts {@code key} and {@code value} and returns the decrypted value 040 * 041 * @param key the key to retrieve {@code value} with 042 * @return the value if it was found and decrypted successfully, else null 043 */ 044 public String secureGet(String key) { 045 return clearTextData.get(key); 046 } 047 048 /** 049 * Gets the clear text data array 050 * 051 * @return the clear text data array 052 */ 053 public HashMap<String, String> getClearTextData() { 054 return clearTextData; 055 } 056 057 /** 058 * Sets the clear text data 059 * 060 * @param clearTextData the clear text data to set 061 */ 062 public void setClearTextData(HashMap<String, String> clearTextData) { 063 this.clearTextData = clearTextData; 064 } 065 066 /** 067 * Gets the crypt data array 068 * 069 * @return the crypt data array 070 */ 071 public HashMap<byte[], byte[]> getCryptData() { 072 return cryptData; 073 } 074 075 /** 076 * Sets the crypt data array 077 * 078 * @param cryptData the crypt data array to set 079 */ 080 public void setCryptData(HashMap<byte[], byte[]> cryptData) { 081 this.cryptData = cryptData; 082 } 083}