Class StringCryptographer
Namespace: OmiyaGames.Cryptography
Assembly: cs.temp.dll.dll
Syntax
public class StringCryptographer : ScriptableObject
Remarks
Copyright (c) 2019-2020 Omiya Games Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Revision | Description |
---|---|
Version: 0.0.0-preview.1 Date: 2/11/2019 Author: Taro Omiya | Initial verison. |
Version: 0.1.0-preview.1 Date: 4/3/2020 Author: Taro Omiya | Converted the class to a package. |
Version: 0.2.2-preview.1 Date: 5/19/2020 Author: Taro Omiya | Fixing license documentation to be more DocFX friendly. |
Constructors
StringCryptographer()
Generates a StringCryptographer with a randomized value for every field, using GetRandomPassword(Int32, String).
Declaration
public StringCryptographer()
StringCryptographer(Int32)
Generates a StringCryptographer with a randomized value for every field, using GetRandomPassword(Int32, String).
Declaration
public StringCryptographer(int passwordLength)
Parameters
Type | Name | Description |
---|---|---|
Int32 | passwordLength | The string length of PasswordHash and SaltKey |
StringCryptographer(String)
Generates a StringCryptographer with PasswordHash set. All other fields are randomized using GetRandomPassword(Int32, String).
Declaration
public StringCryptographer(string passwordHash)
Parameters
Type | Name | Description |
---|---|---|
String | passwordHash | Sets PasswordHash |
StringCryptographer(String, Int32)
Generates a StringCryptographer with PasswordHash set. All other fields are randomized using GetRandomPassword(Int32, String).
Declaration
public StringCryptographer(string passwordHash, int saltKeyLength)
Parameters
Type | Name | Description |
---|---|---|
String | passwordHash | Sets PasswordHash |
Int32 | saltKeyLength | Length of SaltKey |
StringCryptographer(String, String)
Generates a StringCryptographer with PasswordHash and SaltKey set. All other fields are randomized using GetRandomPassword(Int32, String).
Declaration
public StringCryptographer(string passwordHash, string saltKey)
Parameters
Type | Name | Description |
---|---|---|
String | passwordHash | Sets PasswordHash |
String | saltKey | Sets SaltKey |
StringCryptographer(String, String, String)
Generates a StringCryptographer with all fields set.
Declaration
public StringCryptographer(string passwordHash, string saltKey, string ivKey)
Parameters
Type | Name | Description |
---|---|---|
String | passwordHash | Sets PasswordHash |
String | saltKey | Sets SaltKey |
String | ivKey | Sets IvKey |
Fields
AlphaNumericChars
Declaration
public const string AlphaNumericChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
Field Value
Type | Description |
---|---|
String |
AlphaNumericSymbolsChars
Declaration
public const string AlphaNumericSymbolsChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*-_+=?,.`~|(){}[]'\"\\/<>"
Field Value
Type | Description |
---|---|
String |
DefaultPasswordLength
Declaration
public const int DefaultPasswordLength = 32
Field Value
Type | Description |
---|---|
Int32 |
IvKeyBlockSize
Declaration
public const int IvKeyBlockSize = 18
Field Value
Type | Description |
---|---|
Int32 |
Properties
IvKey
Initialization Vector key, used for encryption.
Declaration
public string IvKey { set; }
Property Value
Type | Description |
---|---|
String |
PasswordHash
A random hash used for used for encryption.
Declaration
public string PasswordHash { set; }
Property Value
Type | Description |
---|---|
String |
SaltKey
A salt to make PasswordHash less predictable.
Declaration
public string SaltKey { set; }
Property Value
Type | Description |
---|---|
String |
Methods
Decrypt(String)
Decrypts an encrypted string.
Declaration
public string Decrypt(string encryptedText)
Parameters
Type | Name | Description |
---|---|---|
String | encryptedText | String to decrypt. |
Returns
Type | Description |
---|---|
String | Decrypted string. |
Encrypt(String)
Encrypts a string.
Declaration
public string Encrypt(string plainText)
Parameters
Type | Name | Description |
---|---|---|
String | plainText | The string to encrypt. |
Returns
Type | Description |
---|---|
String | plainText, encrypted. |
GetRandomPassword(Int32, String)
Generates a random password using alphanumeric characters. Taken directly from this StackOverflow post by Eric J.
Declaration
public static string GetRandomPassword(int length, string acceptableChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*-_+=?,.`~|(){}[]'\"\\/<>")
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | Length of the returned password |
String | acceptableChars |
Returns
Type | Description |
---|---|
String | An alphnumeric password |