Key encrypt/decrypt problem

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
GeluHUN
Posts: 7
Joined: Thu 28 Jul 2011 07:46
Location: Budapest, Hungary

Key encrypt/decrypt problem

Post by GeluHUN » Fri 02 Dec 2011 13:30

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

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 05 Dec 2011 09:09

SecureBridge uses CryptoAPI for encrypting data, therefore to solve the problem you should add the ScCryptoAPIStorage unit to the uses clause of your unit.

GeluHUN
Posts: 7
Joined: Thu 28 Jul 2011 07:46
Location: Budapest, Hungary

Post by GeluHUN » Mon 05 Dec 2011 11:10

:oops: Thank you, it works that way! :D

Post Reply