Net Encryption Library
IsStringEncrypted Method
Example 






KellermanSoftware.NetEncryptionLibrary Namespace > Encryption Class : IsStringEncrypted Method
The string to examine
For strings encrypted prior to Version 1.11 set strict = false. It will sometimes give a false positive for some strings.
Returns true if a string is encrypted with the Kellerman Encryption Library
Syntax
'Declaration
 
Public Function IsStringEncrypted( _
   ByVal value As System.String, _
   ByVal strict As System.Boolean _
) As System.Boolean
'Usage
 
Dim instance As Encryption
Dim value As System.String
Dim strict As System.Boolean
Dim value As System.Boolean
 
value = instance.IsStringEncrypted(value, strict)
public System.bool IsStringEncrypted( 
   System.string value,
   System.bool strict
)
public function IsStringEncrypted( 
    value: System.String;
    strict: System.Boolean
): System.Boolean; 
public function IsStringEncrypted( 
   value : System.String,
   strict : System.boolean
) : System.boolean;
public: System.bool IsStringEncrypted( 
   System.string* value,
   System.bool strict
) 
public:
System.bool IsStringEncrypted( 
   System.String^ value,
   System.bool strict
) 

Parameters

value
The string to examine
strict
For strings encrypted prior to Version 1.11 set strict = false. It will sometimes give a false positive for some strings.

Return Value

True if the string is encrypted
Remarks

When strict is on, it looks to see if there is a prefix of @KS@ for the string. When strict is off the string is simply checked to see if it is Base64 encoded. These strings are outside the range of valid Base64 characters or cannot be Base64 decoded and thus are safe to have strict turned off for strings encrypted with previous versions of the Kellerman Encryption Library:

Example
Encryption encryption = new Encryption(); //Trial Mode
//Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode
 
const string password = "MyPassword";
const string unencryptedString = "This is the input";
 
bool isEncrypted = encryption.IsStringEncrypted(unencryptedString, true);
Console.WriteLine("Is unencyrpted string encrypted: {0}", isEncrypted);
 
string encryptedString = encryption.EncryptString(EncryptionProvider.Rijndael, password, unencryptedString);
 
isEncrypted = encryption.IsStringEncrypted(encryptedString, true);
Console.WriteLine("Is unencyrpted string encrypted: {0}", isEncrypted);
Dim encryption As New Encryption() 'Trial Mode
'Dim encryption As New Encryption("place user name here", "place license key here") 'License Mode
 
Const password As String = "MyPassword"
Const unencryptedString As String = "This is the input"
 
Dim isEncrypted As Boolean = encryption.IsStringEncrypted(unencryptedString, True)
Console.WriteLine("Is unencyrpted string encrypted: {0}", isEncrypted)
 
Dim encryptedString As String = encryption.EncryptString(EncryptionProvider.Rijndael, password, unencryptedString)
 
isEncrypted = encryption.IsStringEncrypted(encryptedString, True)
Console.WriteLine("Is unencyrpted string encrypted: {0}", isEncrypted)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Encryption Class
Encryption Members