/// <summary> /// Decrypts the specified instance byte array. /// </summary> /// <param name="instanceArray">Instance byte array submitted for decryption.</param> /// <returns>Object if decryption was successful; null for otherwise.</returns> public static object Decrypt(byte[] instanceArray) { if (instanceArray == null || instanceArray.LongLength == 0) { Logger.Warn("Unable to decrypt null or empty byte array!"); return(null); } if (Logger.IsDebugEnabled) { ASCIIEncoding encoding = new ASCIIEncoding(); Logger.DebugFormat("Decrypting instance: {0}", encoding.GetString(instanceArray)); } byte[] decryptedInstance; try { decryptedInstance = SimpleEncryption.Decrypt(instanceArray, PassPhrase); } catch (Exception exception) { Logger.Error("Problem encountered decrypting the byte array!", exception); return(null); } return(ObjectUtil.ConvertToObject(decryptedInstance)); }
/// <summary> /// Decrypts the specified to decrypt. /// </summary> /// <param name="toDecrypt">To decrypt.</param> /// <returns></returns> public static string Decrypt(string toDecrypt) { if (string.IsNullOrEmpty(toDecrypt)) { Logger.Warn("Unable to decrypt null or empty string instance"); return(null); } return(SimpleEncryption.Decrypt(toDecrypt, PassPhrase)); }
/// <summary> /// Encrypts the specified instance. /// </summary> /// <param name="instance">Object instance submitted for encryption.</param> /// <returns>The value byte[] will be returned if encryption was successful; /// null for otherwise.</returns> public static byte[] Encrypt(object instance) { if (instance == null) { Logger.Warn("Unable to encrypt NULL instance"); return(null); } if (Logger.IsDebugEnabled) { Logger.DebugFormat("Encrypting instance: {0}", instance); } byte[] serializedInstance = ObjectUtil.ConvertToByteArray(instance); if (serializedInstance == null) { return(null); } return(SimpleEncryption.Encrypt(serializedInstance, PassPhrase)); }