Struct ProtectedString
Drop-in replacement for System.String that stores its value encrypted (UTF-8 + Base64 with a per-instance secret) and reports tampering to the
Implements
Namespace: GUPS.AntiCheat.Protected
Assembly: cs.temp.dll.dll
Syntax
public struct ProtectedString
Remarks
String protection is noticeably more expensive than the numeric primitives; reserve it for actually sensitive values rather than every string in the project.
Examples
Use it as a drop-in replacement for System.String:
using GUPS.AntiCheat.Protected;
ProtectedString playerName = "Tim";
playerName += " (admin)"; // operator + works
if (playerName == "Tim (admin)") { /* ... */ } // equality works
string raw = playerName; // implicit conversion to string
Constructors
ProtectedString(String)
Initializes a new protected string with the specified value.
Declaration
public ProtectedString(string _Value = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Value | Initial value. |
Properties
HasIntegrity
Gets a value indicating whether the protected value still has integrity (i.e. the honeypot has not been tampered with).
Declaration
public bool HasIntegrity { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Value
Gets or sets the unobfuscated value.
Declaration
public string Value { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Remarks
Reading the value runs an integrity check; if the honeypot has been tampered with, the
Methods
CheckIntegrity()
Returns true when the honeypot still matches the encrypted value.
Declaration
public bool CheckIntegrity()
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Dispose()
Clears the encrypted value and the secret.
Declaration
public void Dispose()
Equals(Object)
Returns true when this protected string equals the given object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | Object to compare with. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Overrides
GetHashCode()
Returns the hash code of the unobfuscated value.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | Hash code of the unobfuscated value, or |
Overrides
Obfuscate()
Rerolls the secret and re-obfuscates the current value.
Declaration
public void Obfuscate()
OnAfterDeserialize()
Unity deserialization hook; rebuilds the obfuscation state from the deserialized honeypot value.
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
Unity serialization hook; writes the true value into the honeypot field.
Declaration
public void OnBeforeSerialize()
ToString()
Returns the unobfuscated string value.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | The unobfuscated string. |
Overrides
Operators
Addition(ProtectedString, ProtectedString)
Concatenates two protected strings.
Declaration
public static ProtectedString operator +(ProtectedString v1, ProtectedString v2)
Parameters
| Type | Name | Description |
|---|---|---|
| ProtectedString | v1 | First operand. |
| ProtectedString | v2 | Second operand. |
Returns
| Type | Description |
|---|---|
| ProtectedString | A new protected string holding the concatenation of both values. |
Equality(ProtectedString, ProtectedString)
Returns true when both protected strings represent the same text.
Declaration
public static bool operator ==(ProtectedString v1, ProtectedString v2)
Parameters
| Type | Name | Description |
|---|---|---|
| ProtectedString | v1 | First operand. |
| ProtectedString | v2 | Second operand. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Implicit(ProtectedString to String)
Implicitly unwraps a protected string to its string value.
Declaration
public static implicit operator string (ProtectedString _Value)
Parameters
| Type | Name | Description |
|---|---|---|
| ProtectedString | _Value | Protected string to unwrap. |
Returns
| Type | Description |
|---|---|
| System.String | The unobfuscated string value. |
Implicit(String to ProtectedString)
Implicitly wraps a string in a protected string.
Declaration
public static implicit operator ProtectedString(string _Value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Value | Value to wrap. |
Returns
| Type | Description |
|---|---|
| ProtectedString | A protected string holding the given value. |
Inequality(ProtectedString, ProtectedString)
Returns true when the two protected strings represent different text.
Declaration
public static bool operator !=(ProtectedString v1, ProtectedString v2)
Parameters
| Type | Name | Description |
|---|---|---|
| ProtectedString | v1 | First operand. |
| ProtectedString | v2 | Second operand. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|