Error importing DLL

3

I have a DLL made in C #. When importing it to be used on another computer, I find the class. However, her methods are not published;

Follow my code:

using System;
using System.Security.Cryptography;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace PortalRH.DLL
{
[ComVisible(true), ClassInterface(ClassInterfaceType.None),
Guid("00AC4F7E-71B0-4BC7-AD8E-1175CD88457A")]
public class Criptografia 
{
    private string chave = "chave";
    public Criptografia(){}


    // Essa seqüência constante é usada como um valor "salt" para as chamadas de função PasswordDeriveBytes .
    // Este tamanho da IV (em bytes) devem = (KeySize / 8). KeySize padrão é 256, portanto, a IV deve ser
    // 32 bytes de comprimento. Usando uma seqüência de 16 caracteres aqui nos dá 32 bytes quando convertido para um array de bytes.
    private static readonly byte[] initVectorBytes = Encoding.ASCII.GetBytes("tu89geji340t89u2");

    // Esta constante é utilizado para determinar o tamanho da chave do algoritmo de encriptação.
    private const int keysize = 256;

    public static string Encrypt(string plainText, string passPhrase)
    {
        byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
        using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
        {
            byte[] keyBytes = password.GetBytes(keysize / 8);
            using (RijndaelManaged symmetricKey = new RijndaelManaged())
            {
                symmetricKey.Mode = CipherMode.CBC;
                using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                        {
                            cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                            cryptoStream.FlushFinalBlock();
                            byte[] cipherTextBytes = memoryStream.ToArray();
                            return Convert.ToBase64String(cipherTextBytes);
                        }
                    }
                }
            }
        }
    }

    public static string Decrypt(string cipherText, string passPhrase)
    {
        byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
        using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
        {
            byte[] keyBytes = password.GetBytes(keysize / 8);
            using (RijndaelManaged symmetricKey = new RijndaelManaged())
            {
                symmetricKey.Mode = CipherMode.CBC;
                using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes))
                {
                    using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes))
                    {
                        using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
                        {
                            byte[] plainTextBytes = new byte[cipherTextBytes.Length];
                            int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
                            return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
                        }
                    }
                }
            }
        }
    }

}

}

This DLL was sent to another programmer to use its methods. But he could not see the methods of it.

I checked it, and the methods do not appear in the .TLB file that it is using.

    
asked by anonymous 19.01.2015 / 12:44

1 answer

4

"TLB"? So it's trying to consume your DLL as an ActiveX component.

The problem is that COM does not support static methods and when your colleague creates the proxy for your DLL static methods are not included in the proxy.

Remove the static keyword from the declaration of your methods, and your colleague can consume them as an ActiveX object.

Tip: If you do not want to now refactor all your own code that consumes these methods, instead of removing static , declare new instance methods that consume these static methods. More or less like this:

public class Criptografia 
{
    public static string Encrypt(string plainText, string passPhrase)
    { // ... este é o seu método original
        ...
    }

    public string _Encrypt(string plainText, string passPhrase)
    { // ... este é o novo método, que consome o original.
      // ... é este novo método que o seu colega vai consumir
        return Criptografia.Encrypt(plainText, passPhrase);
    }
    ...
}

Of course, your code may look cooler than this, and this is just a suggestion to use during testing.

    
19.01.2015 / 16:24