StringExtensionsEncrypt(String, SymmetricAlgorithm, Byte, Byte, Encoding) Method
Encrypts a text by the provided symmetric algorithm, using a randomly generated key and initialization vector, which are
returned in key and iv parameters, respectively.
Namespace: KGySoft.CoreLibrariesAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
[CLSCompliantAttribute(false)]
public static string Encrypt(
this string text,
SymmetricAlgorithm algorithm,
out byte[] key,
out byte[] iv,
Encoding? encoding = null
)
<ExtensionAttribute>
<CLSCompliantAttribute(false)>
Public Shared Function Encrypt (
text As String,
algorithm As SymmetricAlgorithm,
<OutAttribute> ByRef key As Byte(),
<OutAttribute> ByRef iv As Byte(),
Optional encoding As Encoding = Nothing
) As String
public:
[ExtensionAttribute]
[CLSCompliantAttribute(false)]
static String^ Encrypt(
String^ text,
SymmetricAlgorithm^ algorithm,
[OutAttribute] array<unsigned char>^% key,
[OutAttribute] array<unsigned char>^% iv,
Encoding^ encoding = nullptr
)
[<ExtensionAttribute>]
[<CLSCompliantAttribute(false)>]
static member Encrypt :
text : string *
algorithm : SymmetricAlgorithm *
key : byte[] byref *
iv : byte[] byref *
?encoding : Encoding
(* Defaults:
let _encoding = defaultArg encoding null
*)
-> string
- text String
- The source plain text to encrypt.
- algorithm SymmetricAlgorithm
- A SymmetricAlgorithm instance to be used for encryption.
- key Byte
- Returns the automatically generated key used for encryption.
- iv Byte
- Returns the automatically generated initialization vector 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: .
StringThe encrypted result of
text.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).