public CipherText(byte[] cipherBytes, CipherTextFormat format = CipherTextFormat.HEXADECIMAL) { Text = (format == CipherTextFormat.BASE64) ? Convert.ToBase64String(cipherBytes) : cipherBytes.ToHexString(); Bytes = cipherBytes; Length = Bytes.Length; Format = format; }
public CipherText(string text, CipherTextFormat format) { Text = text; Bytes = (format == CipherTextFormat.BASE64) ? Convert.FromBase64String(text) : text.HexToBytes(); Length = Bytes.Length; Format = format; }
public string Encrypt(PlainText text, string key, CipherTextFormat format = CipherTextFormat.HEXADECIMAL) { byte[] plainBytes = text.Bytes; byte[] expandedKey = ExpandKey(key.ToByteArray(), plainBytes.Length); byte[] cipherBytes = plainBytes.XorWith(expandedKey); return((format == CipherTextFormat.BASE64) ? Convert.ToBase64String(cipherBytes) : cipherBytes.ToHexString()); }
public string Encrypt(ICryptography encryptor, string key, CipherTextFormat format = CipherTextFormat.HEXADECIMAL) { return(encryptor.Encrypt(this, key, format)); }