Skip to content

Instantly share code, notes, and snippets.

@nicocrm
Created October 15, 2021 05:00
Show Gist options
  • Save nicocrm/0207a88e1fc79d8f93df5f90f915a156 to your computer and use it in GitHub Desktop.
Save nicocrm/0207a88e1fc79d8f93df5f90f915a156 to your computer and use it in GitHub Desktop.
Static class containing utilities to decrypt strings encrypted with the SLX RW EL
/// <summary>
/// Static class containing utilities to decrypt strings encrypted with the SLX RW EL
/// </summary>
public class SlxRwEl
{
/// <summary>
/// Decode the specified data.
/// </summary>
/// <param name="data"></param>
/// <param name="key"></param>
/// <returns></returns>
public static String Decrypt(String data, String key)
{
return InvokeRwMethod<String>("RemoveKey", data, key);
}
/// <summary>
/// Decrypt key-less data (only used for RWPASS)
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static String Decrypt(String data)
{
return InvokeRwMethod<String>("Remove", data);
}
/// <summary>
/// Encrypt specified data.
/// </summary>
/// <param name="data"></param>
/// <param name="key"></param>
/// <returns></returns>
public static String Encrypt(String data, String key)
{
return InvokeRwMethod<String>("AddKey", data, key);
}
/// <summary>
/// Invoke late-bound method.
/// TODO: add caching.
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <param name="methodName"></param>
/// <param name="args"></param>
/// <returns></returns>
private static T1 InvokeRwMethod<T1>(string methodName, params object[] args)
{
Type t = Type.GetTypeFromProgID("SLXRWEL.SLXRWEOBJ");
if (t == null)
throw new InvalidOperationException("SLXRWEL is not available.");
object instance = Activator.CreateInstance(t);
try
{
return (T1)t.InvokeMember(methodName, BindingFlags.InvokeMethod, null, instance, args);
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(instance);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment