Gidday,
I am stuck trying to create a COM Callable Wrapper for the class (shell
only) below.
As you can see I have tried to define my interface and it would be all good
if I wasn't passing my enum into the main functions (which are marked public
static). I am unable to create an interface for the enum, and I can't mark
it as public static so not sure how to get the compiler to swallow it.
I'd rather not have to pass the enum to the functions as an integer as I
think this will break intellisense when calling the function (meaning I
don't think it will display the enumerated list which is a nice feature).
Also, I want this component to be stateless so I need to be able to specify
the crypto provider (the enumerated value) as part of the function call.
Lastly, I prefer a declarative approach so not really interested in just
enabling COM functionality under Project -Properties.
Here's what I have so far (roughly - bit of a cut and paste so forgive any
obvious errors):
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace SomeNamespace.Encryption
{
#region COM Callable Wrapper (CCW)
[Guid("F8B65FF9-7D84-4b27-BEC7-8FFF31AA6C5E"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
public interface _Symmetric
{
[DispId(1)] string EncryptString(enumCryptoServiceProvider
enumCryptoProvider, string strClearText, string strKey, string strSalt);
[DispId(2)] string DecryptString(enumCryptoServiceProvider
enumCryptoProvider, string strCipherText, string strKey, string strSalt);
// This wont work because you can't create an interface to a type
//[DispId(3)] enum enumCryptoServiceProvider;
}
#endregion
[Guid("F8B75FD9-7D84-4b27-BEC7-8FFF31AA6C5E"),
ClassInterface(ClassInterfaceType.None), ProgId("App.Class")]
public class Symmetric : _Symmetric
{
#region Declarations and enumerations
public enum enumCryptoServiceProvider : int
{//}
public Symmetric()
{
//return;
}
#endregion
#region Encryption routines
private static SymmetricAlgorithm
GetCryptoProvider(enumCryptoServiceProvider enumCryptoProvider)
{//}
private static void ConfigureOptions(SymmetricAlgorithm objCrypto, string
strKey, string strSalt)
{//}
public static string EncryptString(enumCryptoServiceProvider
enumCryptoProvider, string strClearText, string strKey, string strSalt)
{//}
public static string DecryptString(enumCryptoServiceProvider
enumCryptoProvider, string strCipherText, string strKey, string strSalt)
{//}
#endregion
}
}
Hope all this makes sense.... and thanks in advance...