Использование ассиметричных алгоритмов криптографического преобразования информации в приложениях Windows

Similar documents
LAMPIRAN Listing Program

NATIONAL SENIOR CERTIFICATE GRADE 12

LAMPIRAN A. Foto Alat

2. Design and Development

Delphi Generics.Collections

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ImgList, StdCtrls, Buttons, MPlayer;

Kada se pokrene forma da bude plave boje. Dugme Crtaj krugove da iscrtava slučajan broj N krugova istog poluprečnika r (1/4 visine forme) čiji su

NATIONAL SENIOR CERTIFICATE GRADE12

APPLICATION NOTE: KONSTANTER LSP32K Interface Protocol

GRADE 12 SEPTEMBER 2012 INFORMATION TECHNOLOGY P1 MEMORANDUM

LAMPIRAN A RANGKAIAN SKEMATIK PERANGKAT KERAS

Source code for simulations: 1 of 11

Coding Standards Document

GRADE/GRAAD 11 NOVEMBER 2013 INFORMATION TECHNOLOGY P1 INLIGTINGSTEGNOLOGIE V1 MEMORANDUM

Introduction to the DLL for the USB Interface Board K8061

LAMPIRAN A: LIST PROGRAM

Getting started with Lazarus

NATIONAL SENIOR CERTIFICATE GRADE12

Image. uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls ;

UJIAN AKHIR SEMESTER TEKNIK INFORMATIKA SEKOLAH TINGGI TEKNOLOGI DUTA BANGSA

LAMPIRAN A: DDL DATABASE

NATIONAL SENIOR CERTIFICATE GRADE12

unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

DELPHI FOR ELECTRONIC ENGINEERS. Part 2 Programming a calculator COURSE

NATIONAL SENIOR CERTIFICATE GRADE12

var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Items.LoadFromFile('d:\brojevi.

NATIONAL SENIOR CERTIFICATE GRADE12

GRADE 11 NOVEMBER 2012 INFORMATION TECHNOLOGY P1 INLIGTINGSTEGNOLOGIE V1 MEMORANDUM

Adventures in Messaging

NATIONAL SENIOR CERTIFICATE GRADE 12

LAMPIRAN A. Listing Program. Program pada Borland Delphi 7.0 A-1 Program pada CodeVisionAVR C Compiler A-6

NATIONAL SENIOR CERTIFICATE GRADE 12

LAMPIRAN 1 TATA CARA PENGGUNAAN SOFTWARE ALGORITMA GENETIKA

Аутентификация по рисунку вен руки в мультимодальных биометрических системах

&'()*+,-./0&(1& $ :;

Graphics Programming with GDI and Fonts

LAMPIRAN. uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, XPMan, ExtCtrls, jpeg;

Printing in Delphi 5 IN THIS CHAPTER CHAPTER. The TPrinter Object 420. TPrinter.Canvas 421. Simple Printing 422. Printing a Form 425

ӨЗБЕКСТАН РЕСПУБЛИКАСЫ ҲАЛЫҚ БИЛИМЛЕНДИРИӮ МИНИСТРЛИГИ ӘЖИНИЯЗ АТЫНДАҒЫ НӨКИС МӘМЛЕКЕТЛИК ПЕДАГОГИКА ИНСТИТУТЫ ФИЗИКА-МАТЕМАТИКА ФАКУЛЬТЕТИ

NATIONAL SENIOR CERTIFICATE GRADE 12

Object Pascal Language Guide

Interdisciplinary relations in teaching of programming

THREE. Multiple windows

Информатика и вычислительная техника

(1) Trump (1) Trump (2) (1) Trump ExampleU ExampleP (2) Caption. TrumpU (2) Caption. (3) Image FormTrump. Top 0 Left 0.

UNIT Files. Procedure/Functionand Other Declarations (CONST, TYPE, VAR) can be stored under different Object Pascal Files (Library).

NEAR EAST UNIVERSI FACULTY OF ECONOMICS AND ADMINISTRATIVE SCIENCES DEPARTMENT OF COMPUTER INFORMATION SYSTEMS

ВЫПУСКНАЯ КВАЛИФИКАЦИОННАЯ РАБОТА БАКАЛАВРА

Creating a Webserver in 5 minutes using kbmmw!

12.2 Mixing HLA and MASM/Gas Code in the Same Program In-Line (MASM/Gas) Assembly Code in Your HLA Programs

NEAR EAST UNIVERSITY. Faculty of Engineering. Department of Computer Engineering TIME TABLE DESIGN: DELPHI APPLICATION. Graduation Project COM-400

SENIOR CERTIFICATE EXAMINATION

MesuTher.dproj 07/05/ :56:44

maxbox /09/ :44:02

Pascal: operations on basic data structures (selection) (I) 2.3 Accessing and manipulating data

NATIONAL SENIOR CERTIFICATE GRADE 12

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

Delphi Language Guide

Санкт-Петербургский Государственный Политехнический Университет Факультет Технической Кибернетики Кафедра Информационных Измерительных Технологий

DMX-Dongle II Win16, Win32 & Dos Developer s Guide

For more detailed information on the differences between DelphiScript and Object Pascal, refer to the DelphiScript Reference document.

We are all familiar with the concept of a queue:

LAMPIRAN A LISTING PROGRAM

Windows. mine sweeper Jirai JiraiU.pas JiraiP.dpr. Form Name FormJirai Caption Position podesktopcenter 16.3

AN EXAMPLE FOR THE USE OF BITWISE OPERATIONS IN PROGRAMMING. Krasimir Yordzhev

Part 1 The first steps

«» 68, 19, 1, 41.,,,,,,,... : Delphi. : 1., ё Delphi. 4.. :,,,.,,

Platform Independent Implementation of High Speed Serial Communication Based on FPGA

Math-Net.Ru All Russian mathematical portal

Delphi by Design. One-Step ActiveX - Part 2

Mathematical Modeling in Delphi

12.2 Mixing HLA and MASM/Gas Code in the Same Program In-Line (MASM/Gas) Assembly Code in Your HLA Programs

ОРГАНИЗАЦИЯ ВЫЧИСЛЕНИЙ И ГРАФИЧЕСКОЕ ПРЕДСТАВЛЕНИЕ МЕДИКО-БИОЛОГИЧЕСКОЙ ИНФОРМАЦИИ С ИСПОЛЬЗОВАНИЕМ ПРОГРАММЫ EXCEL

Delphi2Cpp Dr. Detlef Meyer-Eltz

COMPLEX CERTIFICATE POLICIES

ВЫПУСКНАЯ КВАЛИФИКАЦИОННАЯ РАБОТА МАГИСТРА. Силина Дмитрий Игоревича. Бесконфликтная аггрегация даннных на основе дерева в беспроводных сетях.

PDFtext.dll 64 bit-version

judul : dump mysql with delphi - opensource

MesuInstru.dproj 07/05/ :53:24

( )*!+,!)*-!.*, /0!*1(02)3 40*45!6,7! 45!(!18*9 :* -*1) :*() ABC DEFGH DEFG 98* :* J/0K4!6+)))*/!6/1!0,L5+, :*)!! MABC DEFGN!!

The scripting system handles two types of components: Visual and Non-visual components.

Writing Delphi Custom Components

ИСПОЛЬЗОВАНИЕ SCADA-СИСТЕМ В ГОРНОЙ ПРОМЫШЛЕННОСТИ

АВТОМАТИЧЕСКАЯ СЕГМЕНТАЦИЯ ЗАПРОСОВ ПОЛЬЗОВАТЕЛЕЙ С ПОМОЩЬЮ ЖУРНАЛОВ ЩЕЛЧКОВ И СЛОВАРЕЙ

Combining kbmmw and kbmwabd for kbmwabd v and kbmmw v

Math-Net.Ru All Russian mathematical portal

Introduction to Programming Using Java (98-388)

Nhập môn. Friday, January 23, 2004 Quyển 1 HƯỚNG DẪN LẬP TRÌNH DELPHI. Phụ lục

DelphiScript Keywords

Delphi XML-Beispiel-Code

«Approve» The Dean of the Faculty of Radio Engineering, Telecommunications and Communications Medeuov U year

NATIONAL SENIOR CERTIFICATE GRADE 12

Listing Program Tugas Akhir (TugasAkhir.dpr)

NATIONAL SENIOR CERTIFICATE GRADE 12

The information in this document is based on these software and hardware versions:

Some Models of a Distributed Database Management System with Data Replication

sourcecode_of_keisanpro.txt

Starting with Bold for Delphi/Bold for C++ Part 2: Extending Models. By Anthony Richardson 31 October 2001 Revision 1.0

function SortArray(Const VaiArrayOfInteger: TArrayOfInteger; Const

Math-Net.Ru All Russian mathematical portal

Transcription:

Государственное образовательное учреждение высшего профессионального образования «Петербургский государственный университет путей сообщения» Кафедра «Информационные и вычислительные системы» Лабораторная работа 3 По курсу «Методы и средства защиты информации» Использование ассиметричных алгоритмов криптографического преобразования информации в приложениях Windows Вариант 6 Скачано с сайта http://ivc.clan.su Выполнил: студент группы ПВТ-711 Круглов В. А. Проверил: САНКТ-ПЕТЕРБУРГ 2011

Листинг приложения SERVER unit Server; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, FileCtrl, ExtCtrls; type ByteArray = array of byte; TMainForm = class(tform) GroupBox1: TGroupBox; epath: TEdit; btnselectpath: TSpeedButton; GroupBox2: TGroupBox; emessage: TMemo; GridPanel1: TGridPanel; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure btnselectpathclick(sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private Key, ProviderDescriptor: Cardinal; public { Public declarations } MainForm: TMainForm; implementation uses Wcrypt2; {$R *.dfm} procedure TMainForm.Button1Click(Sender: TObject); KeyDescriptor: Cardinal; BufferSize: Integer; Buffer: ByteArray; f: file of byte; CryptGenKey(ProviderDescriptor, AT_KEYEXCHANGE, $02000000, @KeyDescriptor) ShowMessage('Key generation failed!');

Key:=KeyDescriptor; CryptExportKey(KeyDescriptor, 0, PUBLICKEYBLOB, 0, nil, @BufferSize) CryptDestroyKey(KeyDescriptor); ShowMessage('kernel panic!'); CryptExportKey(KeyDescriptor, 0, PUBLICKEYBLOB, 0, @(Buffer[0]), @BufferSize) CryptDestroyKey(KeyDescriptor); Rewrite(f); BlockWrite(f,Buffer[0],BufferSize); procedure TMainForm.Button2Click(Sender: TObject); KeyDescriptor, HashDescriptor: Cardinal; f: file of byte; Buffer, Signature: ByteArray; BufferSize, NewSize: Integer; Text: AnsiString; Reset(f); BufferSize:=FileSize(f); BlockRead(f,Buffer[0],BufferSize); CryptImportKey(ProviderDescriptor,@(Buffer[0]),BufferSize,Key,0,@KeyDescripto r) CryptDestroyKey(Key); Key:=KeyDescriptor; CryptGenKey(ProviderDescriptor, AT_SIGNATURE, $02000000, @KeyDescriptor) ShowMessage('Signature key generation failed!'); CryptExportKey(KeyDescriptor, 0, PUBLICKEYBLOB, 0, nil, @BufferSize) CryptDestroyKey(KeyDescriptor); ShowMessage(IntToStr(GetLastError));

ShowMessage('kernel panic!'); CryptExportKey(KeyDescriptor, 0, PUBLICKEYBLOB, 0, @(Buffer[0]), @BufferSize) CryptDestroyKey(KeyDescriptor); BufferSize:=Length(Buffer); NewSize:=BufferSize; CryptEncrypt(Key,0,true,0,nil,@NewSize,0) ShowMessage('kernel panic!'); SetLength(Buffer,NewSize); CryptEncrypt(Key,0,true,0,@(Buffer[0]),@BufferSize,NewSize) ShowMessage('Encrypting failed!'); Rewrite(f); BlockWrite(f,Buffer[0],NewSize); Text:=eMessage.Text; SetLength(Buffer,Length(ByteArray(Text))); SetLength(Signature,Length(ByteArray(Text))); Move(ByteArray(Text)[0],Buffer[0],Length(ByteArray(Text))); Move(ByteArray(Text)[0],Signature[0],Length(ByteArray(Text))); CryptCreateHash(ProviderDescriptor,CALG_MD5,0,0,@HashDescriptor) ShowMessage('Failed to create hash!'); CryptHashData(HashDescriptor,@(Buffer[0]),Length(Buffer),0) CryptDestroyHash(HashDescriptor); ShowMessage('Failed to make hash!'); BufferSize:=Length(Buffer); NewSize:=BufferSize; CryptEncrypt(Key,0,true,0,nil,@NewSize,0) ShowMessage('kernel panic!'); SetLength(Buffer,NewSize); CryptEncrypt(Key,0,true,0,@(Buffer[0]),@BufferSize,NewSize) ShowMessage('Encrypting failed!');

BufferSize:=Length(Signature); NewSize:=BufferSize; CryptSignHash(HashDescriptor, AT_SIGNATURE, nil, 0, nil, @NewSize) ShowMessage('kernel panic!'); SetLength(Signature,NewSize); CryptSignHash(HashDescriptor, AT_SIGNATURE, nil, 0, @(Signature[0]), @NewSize) ShowMessage('kernel panic!'); BufferSize:=Length(Buffer); NewSize:=Length(Signature); AssignFile(f,ePath.Text+'message'); Rewrite(f); BlockWrite(f,BufferSize,4); BlockWrite(f,Buffer[0],BufferSize); BlockWrite(f,NewSize,4); BlockWrite(f,Signature[0],NewSize); procedure TMainForm.FormCreate(Sender: TObject); ProviderName: Array [0..59] of WideChar; ProviderName:='Microsoft Base Cryptographic Provider v1.0'; CryptAcquireContext(@ProviderDescriptor,nil,@(ProviderName[0]),PROV_RSA_FULL, 0) ShowMessage('Provider not found!'); procedure TMainForm.FormDestroy(Sender: TObject); CryptReleaseContext(ProviderDescriptor,0); procedure TMainForm.btnSelectPathClick(Sender: TObject); Result: String; Result:=ePath.Text; if SelectDirectory('Select shared directory', 'Desktop', Result, [sdnewui, sdnewfolder]) epath.text:=result;

end. CLIENT unit Client; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl, Buttons, ExtCtrls; type ByteArray = array of byte; TMainForm = class(tform) GroupBox1: TGroupBox; btnselectpath: TSpeedButton; epath: TEdit; GroupBox2: TGroupBox; epassword: TEdit; GroupBox3: TGroupBox; emessage: TMemo; GridPanel1: TGridPanel; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure btnselectpathclick(sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private Key, ProviderDescriptor: Cardinal; public { Public declarations } MainForm: TMainForm; implementation uses Wcrypt2; {$R *.dfm} procedure TMainForm.btnSelectPathClick(Sender: TObject); Result: String; Result:=ePath.Text; if SelectDirectory('Select shared directory', 'Desktop', Result, [sdnewui, sdnewfolder]) epath.text:=result;

procedure TMainForm.Button1Click(Sender: TObject); PublicKeyDescriptor: Cardinal; HashDescriptor, KeyDescriptor: Cardinal; f: file of byte; Buffer: ByteArray; BufferSize: Integer; Text: AnsiString; Reset(f); BufferSize:=FileSize(f); BlockRead(f,Buffer[0],BufferSize); CryptImportKey(ProviderDescriptor,@(Buffer[0]),BufferSize,0,0,@PublicKeyDescr iptor) CryptCreateHash(ProviderDescriptor,CALG_MD5,0,0,@HashDescriptor) ShowMessage('Failed to create hash!'); Text:=ePassword.Text; SetLength(Buffer,Length(ByteArray(Text))); Move(ByteArray(Text)[0],Buffer[0],Length(ByteArray(Text))); CryptHashData(HashDescriptor,@(Buffer[0]),Length(Buffer),0) CryptDestroyHash(HashDescriptor); ShowMessage('Failed to make hash!'); CryptDeriveKey(ProviderDescriptor,CALG_RC2,HashDescriptor,CRYPT_EXPORTABLE,@K eydescriptor) CryptDestroyHash(HashDescriptor); ShowMessage('Failed to create key!'); CryptDestroyHash(HashDescriptor); CryptExportKey(KeyDescriptor, PublicKeyDescriptor, SIMPLEBLOB, 0, nil, @BufferSize)

ShowMessage('kernel panic!'); CryptExportKey(KeyDescriptor, PublicKeyDescriptor, SIMPLEBLOB, 0, @(Buffer[0]), @BufferSize) Key:=KeyDescriptor; Rewrite(f); BlockWrite(f,Buffer[0],BufferSize); procedure TMainForm.Button2Click(Sender: TObject); f: file of byte; Buffer, Signature: ByteArray; BufferSize, SignatureSize: Integer; Result: AnsiString; KeyDescriptor, HashDescriptor: Cardinal; Reset(f); BufferSize:=FileSize(f); BlockRead(f,Buffer[0],BufferSize); CryptDecrypt(Key,0,true,0,@(Buffer[0]),@BufferSize) ShowMessage(IntToStr(GetLastError)); ShowMessage('Decrypting failed!'); SetLength(Buffer, BufferSize); CryptImportKey(ProviderDescriptor,@(Buffer[0]),BufferSize,0,0,@KeyDescriptor) AssignFile(f,ePath.Text+'message'); Reset(f); BlockRead(f,BufferSize,4); BlockRead(f,Buffer[0],BufferSize); BlockRead(f,SignatureSize,4); SetLength(Signature,SignatureSize); BlockRead(f,Signature[0],SignatureSize);

CryptDecrypt(Key,0,true,0,@(Buffer[0]),@BufferSize) ShowMessage(IntToStr(GetLastError)); ShowMessage('Dencrypting failed!'); SetLength(Result,BufferSize); Move(Buffer[0],Result[1],BufferSize); emessage.text:=result; CryptCreateHash(ProviderDescriptor,CALG_MD5,0,0,@HashDescriptor) ShowMessage('Failed to create hash!'); CryptHashData(HashDescriptor,@(Buffer[0]),BufferSize,0) CryptDestroyHash(HashDescriptor); ShowMessage('Failed to make hash!'); CryptVerifySignature(HashDescriptor,@(Signature[0]),SignatureSize,KeyDescript or,nil,0) MessageDlg('Signature failed!'#13'error: '+IntToStr(GetLastError), mterror, [mbok], 0); end else MessageDlg('Signature success!', mtinformation, [mbok], 0); procedure TMainForm.FormCreate(Sender: TObject); ProviderName: Array [0..59] of WideChar; ProviderName:='Microsoft Base Cryptographic Provider v1.0'; CryptAcquireContext(@ProviderDescriptor,nil,@(ProviderName[0]),PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) ShowMessage('Provider not found!'); procedure TMainForm.FormDestroy(Sender: TObject); CryptReleaseContext(ProviderDescriptor,0); end.

Краткие выводы