StringExtensions..::..AsNumeric Method
Decodes a numeric encoded string, originally representing a password or sensitive information, back to its textual form. This method reverses the encoding applied by AsNumeric, allowing secure retrieval of the original string from its bigint numeric representation.
Namespace:
System.TextAssembly: Walter.Cypher (in Walter.Cypher.dll)
Syntax
Parameters
- value
- Type: String
The bigint numeric encoded string to be decoded.
Return Value
The original text, typically a password, encoded in the numeric string.Remarks
Examples
Here is a unit test that shows and allows you to validate the security and functional aspects of the encoding/decoding process, allowing you to ensure the method is effective against the most common attack vectors.
The test bellow would generate the following TestContext Messages:
Test1: The Numeric values of the same phrase should result in different values.
The Numeric value of Pa$$word is:766580654759767643676203645868119877711146611148768100 and 6568880678397674436665436852321194736111875911485904100. Equal:False
Test 2:
Expect:''Pa$$word''
Actual:''Pa$$word''
Equal:True
Test 3:
Expect:''Pa$$word''
Actual:''Pa$$word''
Equal:True
Enhanced security of the system by providing variable responses or demonstrating non-deterministic output.
[TestMethod()] public void IsRandomTest() { var secretString = "Pa$word"; var encrypted1 = secretString.AsNumeric(); var encrypted2 = secretString.AsNumeric(); _context.WriteLine($"Test1: The Numeric values of the same phrase should result in different values.\nThe Numeric value of {secretString} is:{encrypted1} and {encrypted2}. Equal:{encrypted1.Equals(encrypted2, StringComparison.InvariantCultureIgnoreCase)}\n\n"); Assert.AreNotEqual(encrypted1,encrypted2); int loopNr = 1; foreach (var decrypted in new string[] { encrypted1.FromNumeric(), encrypted2.FromNumeric() }) { _context.WriteLine($"Test {++loopNr}:\nExpect:''{secretString}''\nActual:''{decrypted}''\nEqual:{secretString.Equals(decrypted,StringComparison.Ordinal)}\n"); Assert.AreEqual(secretString, decrypted); } }