public string Protect(string plaintext, bool toBase64 = false) { if (string.IsNullOrEmpty(plaintext)) { return(string.Empty); } try { if (toBase64) { return(Base256Encoders.EncryptToBase64($"{GetIV()}{plaintext}", CurrentKey.MasterKey)); } return(Base256Encoders.EncryptToBase256($"{GetIV()}{plaintext}", CurrentKey.MasterKey)); } catch { return(string.Empty); } }
public byte[] Protect(byte[] plaintext) { if (plaintext != null && plaintext.Length != 0) { try { string iV = GetIV(); byte[] bytes = Base256Encoders.SecureUtf8Encoding.GetBytes(iV); byte[] array = new byte[bytes.Length + plaintext.Length]; bytes.CopyTo(array, 0); plaintext.CopyTo(array, bytes.Length); return(Base256Encoders.EncryptToBase256(array, CurrentKey.MasterKey)); } catch { return(new byte[0]); } } return(new byte[0]); }