Code Monkey home page Code Monkey logo

delphi-openssl's Introduction

Delphi OpenSSL Library

Delphi wrapper for OpenSSL.

Features

  • Encrypt/Decrypt using RSA algorithm
  • Symmetric cipher routines
  • Base64 encoding e decoding
  • Basic PAM support
  • Generation of pseudo-random bit strings
  • Basic SMIME support
  • Generate RSA KeyPairs in PKCS PEM format

Usage

Encrypt with the public key inside X509 certificate

Command line:

OpenSSL rsautl -encrypt -certin -inkey publiccert.cer -in test.txt -out test.txt.cry

Source code:

var
  RSAUtil :TRSAUtil;
  Cerificate :TX509Cerificate;
begin
  RSAUtil := TRSAUtil.Create;
  try
    Cerificate := TX509Cerificate.Create;
    try
      Cerificate.LoadFromFile('publiccert.cer');
      RSAUtil.PublicKey.LoadFromCertificate(Cerificate);
      RSAUtil.PublicEncrypt('test.txt', 'test.txt.cry');
    finally
      Cerificate.Free;
    end;
  finally
    RSAUtil.Free;
  end;
end;

Encrypt with the public key in PEM format

Command line:

OpenSSL rsautl -encrypt -pubin -inkey publickey.pem -in test.txt -out test.txt.cry

Source code:

var
  RSAUtil :TRSAUtil;
begin
  RSAUtil := TRSAUtil.Create;
  try
    RSAUtil.PublicKey.LoadFromFile('publickey.pem');
    RSAUtil.PublicEncrypt('test.txt', 'test.txt.cry');
  finally
    RSAUtil.Free;
  end;
end;

Decrypt with the private key in PEM format

Command line:

OpenSSL rsautl -decrypt -inkey privatekey.pem -in test.txt.cry -out test.txt

Source code:

var
  RSAUtil :TRSAUtil;
begin
  RSAUtil := TRSAUtil.Create;
  try
    RSAUtil.PrivateKey.OnNeedPassphrase := PassphraseReader;
    RSAUtil.PrivateKey.LoadFromFile('privatekey.pem');
    RSAUtil.PrivateDecrypt('test.txt.cry', 'test.txt');
  finally
    RSAUtil.Free;
  end;
end;

Encrypt with AES256

Command line:

OpenSSL enc -base64 -aes256 -in text.plain -out text.aes256 -k secure

Source code:

var
  EncUtil :TEncUtil;
begin
  EncUtil := TEncUtil.Create;
  try
    EncUtil.UseBase64 := True;
    EncUtil.Passphrase := 'secure';
    EncUtil.Cipher := 'AES-256';
    EncUtil.Encrypt('text.plain', 'text.aes256');
  finally
    EncUtil.Free;
  end;
end;

Todo

  • Symmetric cryptography (partially done)
  • compute hash functions
  • Sign e verify
  • RSA data management
  • Data managing for X509
  • Manage information according to the PKCS #12 standard

Prerequisite

OpenSSL library must be in your system path

Installation

  • Add the source path "Source" to your Delphi project path
  • Run the demo and follow the tutorial

delphi-openssl's People

Contributors

lminuti avatar ganacereddine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.