StringExtensionsEncrypt(String, SymmetricAlgorithm, Byte, Byte, Encoding) Method

Encrypts a text by provided symmetric algorithm, key and initialization vector.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static string Encrypt(
	this string text,
	SymmetricAlgorithm algorithm,
	byte[] key,
	byte[] iv,
	Encoding? encoding = null
)

Parameters

text  String
The source plain text to encrypt.
algorithm  SymmetricAlgorithm
A SymmetricAlgorithm instance to be used for encryption.
key  Byte
Key to be used for encryption.
iv  Byte
Initialization vector to be used for encryption.
encoding  Encoding  (Optional)
An optional Encoding to transcode the text before encryption. If , then the actual UTF-16 encoding will be used, which can be faster and may allocate less memory, but the result may be longer if text contains ASCII characters only, for example. This parameter is optional.
Default value: .

Return Value

String
The encrypted result of text in base64 format.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also