encform.pas
来自「著名的SecureBlackBox控件完整源码」· PAS 代码 · 共 329 行
PAS
329 行
unit EncForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
SBXMLDefs, SBXMLSec, ExtCtrls, Buttons;
type
TfrmEnc = class(TForm)
gbGeneralEnc: TGroupBox;
cmbEncryptionMethod: TComboBox;
lbEncryptionMethod: TLabel;
btnOK: TButton;
btnCancel: TButton;
cbEncryptKey: TCheckBox;
gbKeyInfo: TGroupBox;
lbKeyName: TLabel;
edKeyName: TEdit;
gbKEK: TGroupBox;
rgKEK: TRadioGroup;
lbKeyTransport: TLabel;
lbKeyWrap: TLabel;
cmbKeyTransport: TComboBox;
cmbKeyWrap: TComboBox;
lbEncryptedDataType: TLabel;
cmbEncryptedDataType: TComboBox;
sbKeyFile: TSpeedButton;
edKeyFile: TEdit;
dlgOpen: TOpenDialog;
lbPassphrase: TLabel;
edPassphrase: TEdit;
lbKeyFile: TLabel;
lbMimeType: TLabel;
edMimeType: TEdit;
lbExternalFile: TLabel;
edExternalFile: TEdit;
sbExternalFile: TSpeedButton;
dlgSave: TSaveDialog;
procedure sbExternalFileClick(Sender: TObject);
procedure cmbEncryptedDataTypeClick(Sender: TObject);
procedure sbKeyFileClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure rgKEKClick(Sender: TObject);
procedure cbEncryptKeyClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FLockOpt: Boolean;
function GetExternalFile: string;
procedure SetExternalFile(const Value: string);
function GetMimeType: string;
procedure SetMimeType(const Value: string);
function GetKeyFile: string;
procedure SetKeyFile(const Value: string);
function GetPassphrase: string;
procedure SetPassphrase(const Value: string);
function GetEncryptedDataType: TElXMLEncryptedDataType;
procedure SetEncryptedDataType(const Value: TElXMLEncryptedDataType);
function GetKeyName: string;
procedure SetKeyName(const Value: string);
function GetKeyWrapMethod: TElXMLKeyWrapMethod;
procedure SetKeyWrapMethod(const Value: TElXMLKeyWrapMethod);
function GetKeyTransportMethod: TElXMLKeyTransportMethod;
procedure SetKeyTransportMethod(const Value: TElXMLKeyTransportMethod);
function GetKeyEncryptionType: TElXMLKeyEncryptionType;
procedure SetKeyEncryptionType(const Value: TElXMLKeyEncryptionType);
function GetEncryptKey: Boolean;
procedure SetEncryptKey(const Value: Boolean);
function GetEncryptionMethod: TElXMLEncryptionMethod;
procedure SetEncryptionMethod(const Value: TElXMLEncryptionMethod);
public
procedure UpdateOpt;
property EncryptedDataType: TElXMLEncryptedDataType read GetEncryptedDataType write SetEncryptedDataType;
property EncryptionMethod: TElXMLEncryptionMethod read GetEncryptionMethod write SetEncryptionMethod;
property EncryptKey: Boolean read GetEncryptKey write SetEncryptKey;
property KeyEncryptionType: TElXMLKeyEncryptionType read GetKeyEncryptionType write SetKeyEncryptionType;
property KeyTransportMethod: TElXMLKeyTransportMethod read GetKeyTransportMethod write SetKeyTransportMethod;
property KeyWrapMethod: TElXMLKeyWrapMethod read GetKeyWrapMethod write SetKeyWrapMethod;
property MimeType: string read GetMimeType write SetMimeType;
property ExternalFile: string read GetExternalFile write SetExternalFile;
property KeyName: string read GetKeyName write SetKeyName;
property KeyFile: string read GetKeyFile write SetKeyFile;
property Passphrase: string read GetPassphrase write SetPassphrase;
property LockOpt: Boolean read FLockOpt write FLockOpt;
end;
var
frmEnc: TfrmEnc;
implementation
{$R *.dfm}
{ TfrmEnc }
procedure TfrmEnc.cbEncryptKeyClick(Sender: TObject);
begin
UpdateOpt;
end;
procedure TfrmEnc.cmbEncryptedDataTypeClick(Sender: TObject);
begin
UpdateOpt;
end;
procedure TfrmEnc.FormShow(Sender: TObject);
begin
UpdateOpt;
end;
function TfrmEnc.GetEncryptedDataType: TElXMLEncryptedDataType;
begin
case cmbEncryptedDataType.ItemIndex of
1: Result := xedtContent;
2: Result := xedtExternal;
else
Result := xedtElement;
end;
end;
function TfrmEnc.GetEncryptionMethod: TElXMLEncryptionMethod;
begin
case cmbEncryptionMethod.ItemIndex of
1: Result := xemAES;
2: Result := xemCamellia;
3: Result := xemDES;
4: Result := xemRC4;
else
Result := xem3DES
end;
end;
function TfrmEnc.GetEncryptKey: Boolean;
begin
Result := cbEncryptKey.Checked;
end;
function TfrmEnc.GetExternalFile: string;
begin
Result := edExternalFile.Text;
end;
function TfrmEnc.GetKeyEncryptionType: TElXMLKeyEncryptionType;
begin
if rgKEK.ItemIndex = 1 then
Result := xetKeyWrap
else
Result := xetKeyTransport;
end;
function TfrmEnc.GetKeyFile: string;
begin
Result := edKeyFile.Text;
end;
function TfrmEnc.GetKeyName: string;
begin
Result := edKeyName.Text;
end;
function TfrmEnc.GetKeyTransportMethod: TElXMLKeyTransportMethod;
begin
if cmbKeyTransport.ItemIndex = 0 then
Result := xktRSA15
else
Result := xktRSAOAEP;
end;
function TfrmEnc.GetKeyWrapMethod: TElXMLKeyWrapMethod;
begin
case cmbKeyWrap.ItemIndex of
1: Result := xwmAES128;
2: Result := xwmAES192;
3: Result := xwmAES256;
else
Result := xwm3DES;
end;
end;
function TfrmEnc.GetMimeType: string;
begin
Result := edMimeType.Text;
end;
function TfrmEnc.GetPassphrase: string;
begin
Result := edPassphrase.Text;
end;
procedure TfrmEnc.rgKEKClick(Sender: TObject);
begin
UpdateOpt;
end;
procedure TfrmEnc.sbExternalFileClick(Sender: TObject);
begin
if LockOpt then
begin
dlgSave.FileName := edExternalFile.Text;
if dlgSave.Execute then
edExternalFile.Text := dlgSave.FileName;
end
else
begin
dlgOpen.FileName := edExternalFile.Text;
if dlgOpen.Execute then
edExternalFile.Text := dlgOpen.FileName;
end;
end;
procedure TfrmEnc.sbKeyFileClick(Sender: TObject);
begin
dlgOpen.FileName := edKeyFile.Text;
if dlgOpen.Execute then
edKeyFile.Text := dlgOpen.FileName;
end;
procedure TfrmEnc.SetEncryptedDataType(const Value: TElXMLEncryptedDataType);
begin
case Value of
xedtElement: cmbEncryptedDataType.ItemIndex := 0;
xedtContent: cmbEncryptedDataType.ItemIndex := 1;
xedtExternal: cmbEncryptedDataType.ItemIndex := 2;
end;
end;
procedure TfrmEnc.SetEncryptionMethod(const Value: TElXMLEncryptionMethod);
begin
case Value of
xem3DES: cmbEncryptionMethod.ItemIndex := 0;
xemAES: cmbEncryptionMethod.ItemIndex := 1;
xemCamellia: cmbEncryptionMethod.ItemIndex := 2;
xemDES: cmbEncryptionMethod.ItemIndex := 3;
xemRC4: cmbEncryptionMethod.ItemIndex := 4;
end;
end;
procedure TfrmEnc.SetEncryptKey(const Value: Boolean);
begin
cbEncryptKey.Checked := Value;
end;
procedure TfrmEnc.SetExternalFile(const Value: string);
begin
edExternalFile.Text := Value;
end;
procedure TfrmEnc.SetKeyEncryptionType(const Value: TElXMLKeyEncryptionType);
begin
if Value = xetKeyTransport then
rgKEK.ItemIndex := 0
else
rgKEK.ItemIndex := 1;
end;
procedure TfrmEnc.SetKeyFile(const Value: string);
begin
edKeyFile.Text := Value;
end;
procedure TfrmEnc.SetKeyName(const Value: string);
begin
edKeyName.Text := Value;
end;
procedure TfrmEnc.SetKeyTransportMethod(const Value: TElXMLKeyTransportMethod);
begin
if Value = xktRSA15 then
cmbKeyTransport.ItemIndex := 0
else
cmbKeyTransport.ItemIndex := 1;
end;
procedure TfrmEnc.SetKeyWrapMethod(const Value: TElXMLKeyWrapMethod);
begin
case Value of
xwm3DES: cmbKeyWrap.ItemIndex := 0;
xwmAES128: cmbKeyWrap.ItemIndex := 1;
xwmAES192: cmbKeyWrap.ItemIndex := 2;
xwmAES256: cmbKeyWrap.ItemIndex := 3;
end;
end;
procedure TfrmEnc.SetMimeType(const Value: string);
begin
edMimeType.Text := Value;
end;
procedure TfrmEnc.SetPassphrase(const Value: string);
begin
edPassphrase.Text := Value;
end;
procedure TfrmEnc.UpdateOpt;
begin
rgKEK.Enabled := cbEncryptKey.Checked;
cmbKeyTransport.Enabled := cbEncryptKey.Checked;
lbKeyTransport.Enabled := cmbKeyTransport.Enabled;
cmbKeyWrap.Enabled := cbEncryptKey.Checked;
lbKeyWrap.Enabled := cmbKeyWrap.Enabled;
cmbKeyTransport.Enabled := cbEncryptKey.Checked and (rgKEK.ItemIndex = 0);
lbKeyTransport.Enabled := cmbKeyTransport.Enabled;
cmbKeyWrap.Enabled := cbEncryptKey.Checked and (rgKEK.ItemIndex = 1);
lbKeyWrap.Enabled := cmbKeyWrap.Enabled;
edPassphrase.Enabled := cmbKeyTransport.Enabled;
lbPassphrase.Enabled := edPassphrase.Enabled;
edMimeType.Enabled := (cmbEncryptedDataType.ItemIndex = 2);
lbMimeType.Enabled := edMimeType.Enabled;
edExternalFile.Enabled := (cmbEncryptedDataType.ItemIndex = 2);
lbExternalFile.Enabled := edExternalFile.Enabled;
sbExternalFile.Enabled := edExternalFile.Enabled;
end;
procedure TfrmEnc.FormCreate(Sender: TObject);
begin
EncryptedDataType := xedtElement;
EncryptionMethod := xem3DES;
KeyTransportMethod := xktRSA15;
KeyWrapMethod := xwm3DES;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?