public string Encrypt(string data) { var dataByte = data.ConvertToByteArray(); var encrypted = crypto.Encrypt(dataByte); return(encrypted.ConvertToBase64String()); }
private string EncryptAndSign(string input) { byte[] cipherText = symmetricCryptoProvider.Encrypt(Encoding.Unicode.GetBytes(input)); byte[] hash = hashProvider.Hash(CombineBytes(key, cipherText)); byte[] signedBytes = CombineBytes(hash, cipherText); byte[] hashLength = new byte[] { (byte)hash.Length }; return(Convert.ToBase64String(CombineBytes(hashLength, signedBytes))); }
private static string Encrypt(string plainText) { var src = new MemoryStream(Encoding.UTF8.GetBytes(plainText)); var dst = new MemoryStream(); Aes.Encrypt(dst.AsUnclosable(), src, (int)src.Length); var cipherText = Convert.ToBase64String(dst.GetBuffer(), 0, (int)dst.Length); return(cipherText); }
internal static byte[] EncryptSymmetric(string symmetricInstance, byte[] plaintext, ConfigurationContext context) { ArgumentValidation.CheckForNullReference(symmetricInstance, "symmetricInstance"); ArgumentValidation.CheckForEmptyString(symmetricInstance, "symmetricInstance"); SymmetricCryptoProviderFactory factory = new SymmetricCryptoProviderFactory(context); ISymmetricCryptoProvider symmetricProvider = factory.CreateSymmetricCryptoProvider(symmetricInstance); return(symmetricProvider.Encrypt(plaintext)); }
internal static string EncryptSymmetric(ISymmetricCryptoProvider provider, string plaintext) { if (string.IsNullOrEmpty(plaintext)) { throw new ArgumentException("The value can not be a null or empty string.", "plaintext"); } byte[] bytes = Encoding.Unicode.GetBytes(plaintext); byte[] inArray = provider.Encrypt(bytes); CryptographyUtility.GetRandomBytes(bytes); return(Convert.ToBase64String(inArray)); }
internal static string EncryptSymmetric(ISymmetricCryptoProvider provider, string plaintext) { if (string.IsNullOrEmpty(plaintext)) { throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "plaintext"); } byte[] plainTextBytes = UnicodeEncoding.Unicode.GetBytes(plaintext); byte[] cipherTextBytes = provider.Encrypt(plainTextBytes); CryptographyUtility.GetRandomBytes(plainTextBytes); return(Convert.ToBase64String(cipherTextBytes)); }
public void Store(IMessage msg, ISymmetricCryptoProvider cryptoProvider, ProtocolId protocol) { using (var src = new MemoryStream()) { var srcWrap = src.AsUnclosable(); msg.Save(srcWrap, protocol); srcWrap.Seek(0, SeekOrigin.Begin); cdataWrap.Seek(0, SeekOrigin.Begin); cdataWrap.SetLength(0); cryptoProvider.Encrypt(cdataWrap, srcWrap, (int)src.Length); iv = cryptoProvider.IV; } }
public string Encrypt(string input) { byte[] hashLength; byte[] signedBytes; try { var cipherText = _mSymmetricCryptoProvider.Encrypt(Encoding.Unicode.GetBytes(input)); var hash = _mHashProvider.Hash(CombineBytes(_key, cipherText)); signedBytes = CombineBytes(hash, cipherText); hashLength = new[] { Convert.ToByte(hash.Length) }; } catch (Exception) { throw new ApplicationException("encrypt method failed"); } return(Convert.ToBase64String(CombineBytes(hashLength, signedBytes))); }
/// <summary> /// Encrypts a secret using a specified symmetric cryptography provider. /// </summary> /// <param name="symmetricInstance">A symmetric instance from configuration.</param> /// <param name="plaintext">The input for which you want to encrypt.</param> /// <returns>The resulting cipher text.</returns> public static byte[] EncryptSymmetric(string symmetricInstance, byte[] plaintext) { if (string.IsNullOrEmpty(symmetricInstance)) { throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "symmetricInstance"); } try { SymmetricCryptoProviderFactory factory = new SymmetricCryptoProviderFactory(ConfigurationSourceFactory.Create()); ISymmetricCryptoProvider symmetricProvider = factory.Create(symmetricInstance); return(symmetricProvider.Encrypt(plaintext)); } catch (ConfigurationErrorsException configurationException) { TryLogSymmetricConfigurationError(configurationException, symmetricInstance); throw; } }
/// <summary> /// Encrypts the data passed to this method according to the correct symmetric cryptographic /// algorithm as defined in configuration /// </summary> /// <param name="plaintext">Data to be encrypted</param> /// <returns>Encrypted data</returns> public byte[] Encrypt(byte[] plaintext) { return(symmetricCrytoProvider.Encrypt(plaintext)); }
/// <summary> /// Encrypts the data passed to this method according to the correct symmetric cryptographic /// algorithm as defined in configuration /// </summary> /// <param name="plaintext">Data to be encrypted</param> /// <returns>Encrypted data</returns> public byte[] Encrypt(byte[] plaintext) { ISymmetricCryptoProvider provider = CreateProvider(); return(provider.Encrypt(plaintext)); }
/// <summary> /// Encrypts a secret using a specified symmetric cryptography provider. /// </summary> /// <param name="symmetricInstance">A symmetric instance from configuration.</param> /// <param name="plaintext">The input for which you want to encrypt.</param> /// <returns>The resulting cipher text.</returns> public override byte[] EncryptSymmetric(string symmetricInstance, byte[] plaintext) { ISymmetricCryptoProvider symmetricProvider = GetSymmetricCryptoProvider(symmetricInstance); return(symmetricProvider.Encrypt(plaintext)); }
internal static string EncryptSymmetric(ISymmetricCryptoProvider provider, string plaintext) { if (string.IsNullOrEmpty(plaintext)) throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "plaintext"); byte[] plainTextBytes = UnicodeEncoding.Unicode.GetBytes(plaintext); byte[] cipherTextBytes = provider.Encrypt(plainTextBytes); CryptographyUtility.GetRandomBytes(plainTextBytes); return Convert.ToBase64String(cipherTextBytes); }
internal static string EncryptSymmetric(ISymmetricCryptoProvider provider, string plaintext) { if (string.IsNullOrEmpty(plaintext)) { throw new ArgumentException("The value can not be a null or empty string.", "plaintext"); } byte[] bytes = Encoding.Unicode.GetBytes(plaintext); byte[] inArray = provider.Encrypt(bytes); CryptographyUtility.GetRandomBytes(bytes); return Convert.ToBase64String(inArray); }