Crypt - Leo-Corporation/LeoCorpLibrary GitHub Wiki
To use the following methods, you need to use the version 2.6 or higher of LeoCorpLibrary, and put this on top of your code file:
C#
using LeoCorpLibrary;
VB
Imports LeoCorpLibrary
This function is available in version 2.6 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
The Encrypt()
method allows you to encrypt a string
. It returns a string
value.
It's in:
LeoCorpLibrary.Crypt.Encrypt()
This method has a few arguments:
Type | Argument | Description |
---|---|---|
string | source | The string to encrypt |
string | key | The key that will be used to encrypt and decrypt the string |
Here's an example of usage:
C#
string s = "Hello!";
string encrypted = LeoCorpLibrary.Crypt.Encrypt(s, "ABC123");
// Output: jqPW4uxt8hk=
VB
Dim s As String = "Hello!"
Dim encrypted As String = LeoCorpLibrary.Crypt.Encrypt(s, "ABC123")
' Output: jqPW4uxt8hk=
This function is available in version 2.6 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
The Decrypt()
method allows you to decrypt an encrypted string. It returns a string
value.
It's in:
LeoCorpLibrary.Crypt.Decrypt()
This method has a few arguments:
Type | Argument | Description |
---|---|---|
string | encrypt | The encrypted string |
string | key | The key that will be used to encrypt and decrypt the string |
Here's an example of usage:
C#
string encrypted = "jqPW4uxt8hk=";
string decrypted = LeoCorpLibrary.Crypt.Decrypt(encrypted, "ABC123");
// Output: Hello!
VB
Dim encrypted As String = "jqPW4uxt8hk="
Dim decrypted As String = LeoCorpLibrary.Crypt.Decrypt(encrypted, "ABC123")
' Output: Hello!
This function is available in version 3.3 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
The EncryptRSA()
method allows you to ecnrypt a string using RSA encryption. It returns a byte[]
value.
It's in:
LeoCorpLibrary.Crypt.EncryptRSA()
This method has a few arguments:
Type | Argument | Description |
---|---|---|
string | str | The string to encrypt |
RSAParameters | rsaParameters | The RSA key |
Here's an example of usage:
C#
using System.Security.Cryptography;
RSACryptoServiceProvider cryptoServiceProvider = new RSACryptoServiceProvider();
string str = "LeoCorpLibrary";
byte[] encrypt = Crypt.EncryptRSA(str, cryptoServiceProvider.ExportParameters(false));
Console.WriteLine($"Raw: {str}\nEncrypted: {Crypt.ConvertBytesToString(encrypt)}");
VB
Imports System.Security.Cryptography
Dim cryptoServiceProvider As RSACryptoServiceProvider = New RSACryptoServiceProvider()
Dim str As String = "LeoCorpLibrary"
Dim encrypt As Byte() = Crypt.EncryptRSA(str, cryptoServiceProvider.ExportParameters(False))
Console.WriteLine($"Raw: " + str + "\nEncrypted: " + Crypt.ConvertBytesToString(encrypt))
This function is available in version 3.3 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
The DecryptRSA()
method allows you to decrypt a string using RSA encryption. It returns a byte[]
value.
It's in:
LeoCorpLibrary.Crypt.DecryptRSA()
This method has a few arguments:
Type | Argument | Description |
---|---|---|
byte[] | encrypt | The encrypted string |
RSAParameters | rsaParameters | The RSA key |
Here's an example of usage:
C#
using System.Security.Cryptography;
RSACryptoServiceProvider cryptoServiceProvider = new RSACryptoServiceProvider();
string str = "LeoCorpLibrary";
byte[] encrypt = Crypt.EncryptRSA(str, cryptoServiceProvider.ExportParameters(false));
byte[] decrypt = Crypt.DecryptRSA(encrypt, cryptoServiceProvider.ExportParameters(true));
Console.WriteLine($"Raw: {str}\nEncrypted: {Crypt.ConvertBytesToString(encrypt)}\nDecrypted: {Crypt.ConvertBytesToString(decrypt)}");
VB
Imports System.Security.Cryptography
Dim cryptoServiceProvider As RSACryptoServiceProvider = New RSACryptoServiceProvider()
Dim str As String = "LeoCorpLibrary"
Dim encrypt As Byte() = Crypt.EncryptRSA(str, cryptoServiceProvider.ExportParameters(False))
Dim decrypt As Byte() = Crypt.DecryptRSA(encrypt, cryptoServiceProvider.ExportParameters(True))
Console.WriteLine($"Raw: " + str + "\nEncrypted: " + Crypt.ConvertBytesToString(encrypt) + "\nDecrypted: " + Crypt.ConvertBytesToString(decrypt))
This function is available in version 3.3 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
The EncryptAES()
method allows you to encrypt a string using AES encryption. It returns a string
value.
It's in:
LeoCorpLibrary.Crypt.EncryptAES()
This method has a few arguments:
Type | Argument | Description |
---|---|---|
string | str | The string to ecnrypt |
string | key | The key that will be used to encrypt and decrypt the string |
Here's an example of usage:
C#
string str = "LeoCorpLibrary";
string encrypt = Crypt.EncryptAES(str, "key");
string decrypt = Crypt.DecryptAES(encrypt, "key");
Console.WriteLine($"Raw: {str}\nEncrypted: {encrypt}");
VB
Dim str As String = "LeoCorpLibrary"
Dim encrypt As String = Crypt.EncryptAES(str, "key")
Dim decrypt As String = Crypt.DecryptAES(encrypt, "key")
Console.WriteLine("Raw: " + str + "\nEncrypted: " + encrypt)
This function is available in version 3.3 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
The DecryptAES()
method allows you to decrypt a string using AES ecnryption. It returns a string
value.
It's in:
LeoCorpLibrary.Crypt.Decrypt()
This method has a few arguments:
Type | Argument | Description |
---|---|---|
string | encrypted | The encrypted string |
string | key | The key that will be used to encrypt and decrypt the string |
Here's an example of usage:
C#
string str = "LeoCorpLibrary";
string encrypt = Crypt.EncryptAES(str, "key");
string decrypt = Crypt.DecryptAES(encrypt, "key");
Console.WriteLine($"Raw: {str}\nEncrypted: {encrypt}\nDecrypted: {decrypt}");
VB
Dim str As String = "LeoCorpLibrary"
Dim encrypt As String = Crypt.EncryptAES(str, "key")
Dim decrypt As String = Crypt.DecryptAES(encrypt, "key")
Console.WriteLine("Raw: " + str + "\nEncrypted: " + encrypt + "\nDecrypted: " + decrypt)
The Encrypt()
and Decrypt()
methods are also available as extensions of the string
type. They can be used when you import the LeoCorpLibrary.Extensions
namespace.
Click here to go to the Extensions page.