EP_ProtectedStringByKey
The EP_ProtectedStringByKey function returns protected strings. See also Protection Features - Protected Strings.
Parameters
- Key - a pointer to the null terminated string that contains a key of the protected string.
- Buffer - a pointer to the buffer for the protected string. If this parameter is NULL, the function returns the necessary size of the buffer.
- Len - the size of the buffer for the protected string.
Return Value
The function returns the size of the buffer for a protected string or 0 if the function fails.
Remark
The function fails in the following cases:
- there is no protected string with the specified Key;
- the application is not protected.
Definition
Show/Hide C++ function definition
extern "C" __declspec( dllimport ) __stdcall int EP_ProtectedStringByKey( char* Key, char* Buffer, int Len);
Show/Hide Delphi function definition
function EP_ProtectedStringByKey(Key : PAnsiChar; Buffer : pointer; Len : integer) : integer; stdcall;
Show/Hide Visual Basic function definition
Public Declare Function EP_ProtectedStringByKey Lib "enigma_ide.dll" (ByVal Key As String, ByVal Str As String, ByVal Length As Byte) As Byte
Show/Hide C# (.NET) function definition
public class Enigma_IDE
{
[DllImport("enigma_ide.dll", CallingConvention = CallingConvention.StdCall)]
public static extern Int32 EP_ProtectedStringByKey(string Key, IntPtr Buffer, Int32 Len);
}
Examples
Show/Hide Delphi function example
uses
enigma_ide;
procedure TForm1.FormShow(Sender: TObject);
var
str : shortstring;
len : byte;
arr : array [0..MAX_STRING_SIZE - 1] of char;
buflen : integer;
buf : pointer;
begin
len := EP_ProtectedStringByKey('fyi6z02Y', @str[1], sizeof(str));
if len > 0 then
begin
str[0] := char(len);
Edit1.Text := str;
end;
ZeroMemory(@arr, sizeof(arr));
if EP_ProtectedStringByID(1, @arr, sizeof(arr)) > 0 then
begin
Edit2.Text := arr;
end;
buflen := EP_ProtectedStringByKey('26Lu66Er', nil, 0);
if buflen > 0 then
begin
GetMem(buf, buflen + 1);
ZeroMemory(buf, buflen + 1);
if EP_ProtectedStringByKey('26Lu66Er', buf, buflen) > 0 then
begin
Edit3.Text := PAnsiChar(buf);
end;
FreeMem(buf);
end;
end;
Show/Hide C# (.NET) function example
public class Enigma_IDE
{
public static string EP_ProtectedStringByKeyAsAnsiString(string Key)
{
Int32 len = EP_ProtectedStringByKey(Key, IntPtr.Zero, 0);
if (len > 0)
{
byte[] buffer = new byte[len];
if (EP_ProtectedStringByKey(Key, Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0), len) > 0)
{
return Encoding.ASCII.GetString(buffer);
}
}
return string.Empty;
}
public static string EP_ProtectedStringByKeyAsWideString(string Key)
{
Int32 len = EP_ProtectedStringByKey(Key, IntPtr.Zero, 0);
if (len > 0)
{
byte[] buffer = new byte[len];
if (EP_ProtectedStringByKey(Key, Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0), len) > 0)
{
return Encoding.Unicode.GetString(buffer);
}
}
return string.Empty;
}
}
private void Form1_Shown(object sender, EventArgs e)
{
textBox1.Text = Enigma_IDE.EP_ProtectedStringByKeyAsAnsiString("fyi6z02Y");
textBox2.Text = Enigma_IDE.EP_ProtectedStringByKeyAsWideString("26Lu66Er");
}
Show/Hide Visual Basic function example
Private Sub Form_Load()
Dim Lenght As Byte
Dim Str As String
Length = EP_ProtectedStringByKey("fyi6z02Y", vbNullString, 0)
Str = String$(Length, 0)
If EP_ProtectedStringByKey("fyi6z02Y", Str, Length) > 0 Then
Text1.Text = Str
End If
Length = EP_ProtectedStringByID(1, vbNullString, 0)
Str = String$(Length, 0)
If EP_ProtectedStringByID(1, Str, Length) > 0 Then
Text2.Text = Str
End If
Length = EP_ProtectedStringByKey("26Lu66Er", vbNullString, 0)
Str = String$(Length, 0)
If EP_ProtectedStringByKey("26Lu66Er", Str, Length) > 0 Then
Text3.Text = Str
End If
See function examples in the installation folder, Examples\ProtectedStrings subfolder.