Skip to main content
1 of 2

Reverse Engineering an Encryption Algorithm

I have a program that has the ability to encrypt files and I want to be able to create a program that can read these files. I believe it uses a Blowfish encryption, but I'm not certain on that. How can I find the type of encryption used and its key?

Using Reflector, I was able to find the following code:

public static unsafe string Encrypt(string text)
{
    string str;
    basic_string<char,std::char_traits<char>,std::allocator<char> > local2;
    sbyte modopt(IsSignUnspecifiedByte)* numPtr = (sbyte modopt(IsSignUnspecifiedByte)*) Marshal.StringToHGlobalAnsi(text);
    std.basic_string<char,std::char_traits<char>,std::allocator<char> >.{ctor}(&local2, numPtr);
    try
    {
        basic_string<char,std::char_traits<char>,std::allocator<char> > local;
        IntPtr hglobal = new IntPtr(numPtr);
        Marshal.FreeHGlobal(hglobal);
        basic_string<char,std::char_traits<char>,std::allocator<char> >* localPtr = _Encrypt(&local, (basic_string<char,std::char_traits<char>,std::allocator<char> > modopt(IsConst)* modopt(IsImplicitlyDereferenced)) &local2);
        try
        {
            str = new string(std.basic_string<char,std::char_traits<char>,std::allocator<char> >.c_str((basic_string<char,std::char_traits<char>,std::allocator<char> > modopt(IsConst)* modopt(IsConst) modopt(IsConst)) localPtr));
        }
        fault
        {
            ___CxxCallUnwindDtor(std.basic_string<char,std::char_traits<char>,std::allocator<char> >.{dtor}, (void*) &local);
        }
        std.basic_string<char,std::char_traits<char>,std::allocator<char> >.{dtor}(&local);
    }
    fault
    {
        ___CxxCallUnwindDtor(std.basic_string<char,std::char_traits<char>,std::allocator<char> >.{dtor}, (void*) &local2);
    }
    std.basic_string<char,std::char_traits<char>,std::allocator<char> >.{dtor}(&local2);
    return str;
}

I notice it also references this, but I don't understand what it does at all...

[PreserveSig, MethodImpl(MethodImplOptions.Unmanaged, MethodCodeType=MethodCodeType.Native), SuppressUnmanagedCodeSecurity]
internal static unsafe basic_string<char,std::char_traits<char>,std::allocator<char> >* modreq(IsUdtReturn) modopt(CallConvCdecl) _Encrypt(basic_string<char,std::char_traits<char>,std::allocator<char> >*, basic_string<char,std::char_traits<char>,std::allocator<char> > modopt(IsConst)* modopt(IsImplicitlyDereferenced));

I'm still new to desktop programming, my only programming experience is mostly with web-based technologies and the absolute basics of C++. I've never gotten into reverse engineering before either. So please be gentle and thorough in your response as I'd really like to learn.