Net Encryption Library
IsFileEncrypted Method
Example 






KellermanSoftware.NetEncryptionLibrary Namespace > Encryption Class : IsFileEncrypted Method
The path to the file
Set strict equals false for files encrypted prior to version 1.11
Returns true if a file is Encrypted by the Kellerman Software Encryption Library
Syntax
'Declaration
 
Public Function IsFileEncrypted( _
   ByVal filePath As System.String, _
   ByVal strict As System.Boolean _
) As System.Boolean
'Usage
 
Dim instance As Encryption
Dim filePath As System.String
Dim strict As System.Boolean
Dim value As System.Boolean
 
value = instance.IsFileEncrypted(filePath, strict)
public System.bool IsFileEncrypted( 
   System.string filePath,
   System.bool strict
)
public function IsFileEncrypted( 
    filePath: System.String;
    strict: System.Boolean
): System.Boolean; 
public function IsFileEncrypted( 
   filePath : System.String,
   strict : System.boolean
) : System.boolean;
public: System.bool IsFileEncrypted( 
   System.string* filePath,
   System.bool strict
) 
public:
System.bool IsFileEncrypted( 
   System.String^ filePath,
   System.bool strict
) 

Parameters

filePath
The path to the file
strict
Set strict equals false for files encrypted prior to version 1.11

Return Value

True if the file is encrypted
Remarks

When strict is on, it looks to see if there is a prefix of @KS@ for the file. When strict is off the file is simply checked to see if it is Base64 encoded. These file types are outside the range of valid Base64 characters and thus are safe to have strict turned off for files 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
 
File.WriteAllText("input.txt", "This is a test");
 
bool isEncrypted = encryption.IsFileEncrypted("input.txt", true);
Console.WriteLine("Is input file encrypted: {0}", isEncrypted);
 
encryption.EncryptFile(EncryptionProvider.Rijndael, "My Password", "input.txt", "encrypted.txt", false);
 
isEncrypted = encryption.IsFileEncrypted("encrypted.txt", true);
Console.WriteLine("Is encrypted file 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
 
File.WriteAllText("input.txt", "This is a test")
 
Dim isEncrypted As Boolean = encryption.IsFileEncrypted("input.txt", True)
Console.WriteLine("Is input file encrypted: {0}", isEncrypted)
 
encryption.EncryptFile(EncryptionProvider.Rijndael, "My Password", "input.txt", "encrypted.txt", False)
 
isEncrypted = encryption.IsFileEncrypted("encrypted.txt", True)
Console.WriteLine("Is encrypted file 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