Skip to content

Crypto helper

tomdam edited this page Jun 17, 2020 · 1 revision

When writing C# scripts that need to connect to external systems like SharePoint, it is sometimes useful to save the code for authentication in csx file, so you don't have to type it next time you need to connect. This means that you need to save your email and password in csx file. In order to avoid saving sensitive data in clear text, SPCoder has the mechanism for encryption/decryption.

Once you encrypt your string (username, password, clientID, client secret, etc.), you can save the encrypted version in csx file and you can decrypt it using either the CryptoHelper window or the utility method main.Decrypt("ENCRYPTEDVALUE").

Important note: SPCoder uses the System MachineKey for encryption/decription, so the strings can be decrypted only on the machine where they have been encrypted.

This is the example of encrypt/decrypt usage in SPCoder:

string mySecret = main.Encrypt("my secret string");
Console.WriteLine(mySecret);

string original = main.Decrypt(mySecret);
Console.WriteLine(original);

There is also the helper window that can be used for same thing. It can be opened from main menu Windows -> Crypto helper:

Crypto