Page 1 of 1

Key encrypt/decrypt problem

Posted: Fri 02 Dec 2011 13:30
by GeluHUN
Hi!

I have tryed to use the TScKey-s encrypt and decrypt methodes, but I get a puzzling error: EScError: "Method is not overridden in the inherited class". Delphi XE, SC version 3.00.0.6. Error is at the Key.Encrypt line, callstack:
TScStorage.Encrypt
TScKey.Enrcypt
TForm1.Button3Click

What is wrong? :shock: :shock: :oops:

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ScBridge, ScSSHUtil;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    Key: TScKey;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Key.Generate(aaRSA, 1024);
  Key.ExportTo('key1.ssl', False, 'xxx');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Key.ImportFrom('key1.ssl', 'xxx');
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  B: TArray;
  S: string;
begin
  B := TEncoding.Unicode.GetBytes('message');
  B := Key.Encrypt(B);
  S := TEncoding.Unicode.GetString(B);
  B := TEncoding.Unicode.GetBytes(S);
  B := Key.Decrypt(B);
  ShowMessage(TEncoding.Unicode.GetString(B));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Key := TScKey.Create(nil);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Key.Free;
end;

end.
Thank you!
Peter

Posted: Mon 05 Dec 2011 09:09
by Dimon
SecureBridge uses CryptoAPI for encrypting data, therefore to solve the problem you should add the ScCryptoAPIStorage unit to the uses clause of your unit.

Posted: Mon 05 Dec 2011 11:10
by GeluHUN
:oops: Thank you, it works that way! :D