#1 Re: Other components » Using SynCrypto (AES256 CBC PKCS#7) » 2016-07-08 19:20:32

I confirm it was that (the IVAtBeginning parameter). Thanks.

#2 Re: Other components » Using SynCrypto (AES256 CBC PKCS#7) » 2016-07-08 08:01:41

I have a problem when trying to decrypt some data by C# implementation of AES.

Suppose I use the following snippet to encrypt some data in Delphi (using SynCrypto):

var
  KeyStr: AnsiString;
  Key: TSHA256Digest;
  IVStr: AnsiString;
  IV: TAESBlock;

procedure TForm1.btnEncryptClick(Sender: TObject);
var
  AES: TAESCBC;
  InBytes, OutBytes: TBytes;
  FileStream: TFileStream;
  Seed: AnsiString;
begin
  KeyStr := '12345678901234567890123456789012';
  IVStr := '1234567890123456';
  CopyMemory(@Key, @KeyStr[1], 32);
  CopyMemory(@IV, @IVStr[1], 16);

  FileStream := TFileStream.Create('input.dat', fmOpenRead);
  SetLength(InBytes, FileStream.Size);
  FileStream.Read(InBytes[0], FileStream.Size);
  FreeAndNil(FileStream);

  AES := TAESCBC.Create(Key, 256);
  AES.IV := IV;
  OutBytes := AES.EncryptPKCS7(InBytes, True);
  FreeAndNil(AES);

  FileStream := TFileStream.Create('output.aes', fmCreate);
  FileStream.Size := Length(OutBytes);
  FileStream.Position := 0;
  FileStream.Write(OutBytes[0], Length(OutBytes));
  FreeAndNil(FileStream);
end;

Then I use the following program in C# to decrypt the data:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static public void aesDecryptFile(string inputFile, string outputFile)
        {
            FileStream inputStream = null;
            FileStream outputStream = null;
            CryptoStream cryptoStream = null;

            try
            {
                byte[] key = Encoding.ASCII.GetBytes("12345678901234567890123456789012");
                byte[] vec = Encoding.ASCII.GetBytes("1234567890123456");

                outputStream = new FileStream(outputFile, FileMode.Create);

                AesManaged aesCrypto = new AesManaged();
                aesCrypto.BlockSize = 8 * 16;
                aesCrypto.KeySize = 8 * 32;
                aesCrypto.Padding = PaddingMode.PKCS7;
                aesCrypto.Mode = CipherMode.CBC;
                aesCrypto.IV = vec;

                cryptoStream = new CryptoStream(outputStream, aesCrypto.CreateDecryptor(key, vec), CryptoStreamMode.Write);

                inputStream = new FileStream(inputFile, FileMode.Open);

                int length;
                byte[] buffer = new byte[16];

                while ((length = inputStream.Read(buffer, 0, 16)) != 0)
                {
                    cryptoStream.Write(buffer, 0, length);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (cryptoStream != null)
                {
                    cryptoStream.Close();
                }

                if (outputStream != null)
                {
                    outputStream.Close();
                }

                if (inputStream != null)
                {
                    inputStream.Close();
                }
            }
        }

        static void Main(string[] args)
        {
            aesDecryptFile("output.aes", "output.dat");
        }
    }
}

In the result I get the input data but with some trash in the beginning of the output file.


Can you suggest something ?

#3 Other components » Using SynCrypto (AES256 CBC PKCS#7) » 2016-06-28 15:31:51

cedo
Replies: 4

Hello

I have to crypt some data using AES with the following parameters:

Key Size: 256 bits / 32 bytes
Cipher Mode: CBC (Chain Block Chaining)
Padding: PKCS#7
Block Size: 16 bytes
Initialization Vector: 16 bytes

I don't know how to use SynCrypto to do that. Can you help me ?

#4 Re: PDF Engine » How to set up non-printable elements on PDF document ? » 2014-11-18 21:07:22

I think of non-printable warterwarks, text or graphics (an advertisement). And what about comments and annotations ? How can I use comments and annotations ?

#5 PDF Engine » How to set up non-printable elements on PDF document ? » 2014-11-18 14:13:20

cedo
Replies: 2

I would like to know if it is possible to put the non printable layers in the PDF document (for example an advertisement) ? How can I do this ?

#6 PDF Engine » Assertion failure when saving to file » 2013-05-06 09:21:31

cedo
Replies: 1

Suppose I have the following EMF file:
https://docs.google.com/file/d/0B5Z5axE … sp=sharing

At the time of convetring to PDF file I get the following message:
"(...) Assertion failure (...\SynPDF.pas, line 8890)"

procedure TPdfEnum.SaveDC;
begin
  Assert(nDC<high(DC));
  DC[nDC+1] := DC[nDC];
  inc(nDC);
end;

What is wrong with the file ?

#7 Re: PDF Engine » Problem with drawing metafile » 2013-01-16 08:02:27

In my opinion EmfExplorer works fine, but you have to switch off "GDI+" option:
https://docs.google.com/file/d/0B5Z5axE … 1XNkE/edit

As you can see there aren't any boxes in the attached screenshoot.

#8 Re: PDF Engine » Problem with drawing metafile » 2013-01-15 16:04:38

I don't know how it is drawn. I got the metafile from ministry of treasures and I have to use it as background in my report.

#10 PDF Engine » Problem with drawing metafile » 2013-01-15 14:53:40

cedo
Replies: 7

Hello

We have the following code:

const
  OutputFileName = 'test.pdf';
  InputFileName = 'test.emf';
var
  PdfDoc: TPDFDocumentGDI;
  PdfPage: TPdfpage;
  Emf: TMetafile;
begin
  Emf := TMetafile.Create();
  Emf.LoadFromFile(InputFileName);

  PdfDoc := TPdfDocumentGDI.Create;
  PdfDoc.CompressionMethod := cmFlateDecode;
  PdfDoc.DefaultPaperSize := psUserDefined;
  PdfPage := PdfDoc.AddPage();
  PdfPage.PageWidth := Round(72 * Emf.MMWidth / 2540);
  PdfPage.PageHeight := Round(72 * Emf.MMHeight / 2540);
  PdfDoc.VCLCanvas.StretchDraw(Rect(0, 0, Round(Screen.PixelsPerInch * Emf.MMWidth / 2540), Round(Screen.PixelsPerInch * Emf.MMHeight / 2540)), Emf);
  PdfDoc.SaveToFile(OutputFileName);
  PdfDoc.Free();

  FreeAndNil(Emf);
end;

You can download my metafile from here:
https://docs.google.com/file/d/0B5Z5axE … dCN00/edit

The ouput file ha some artefacts (unnecessary frames):
https://docs.google.com/file/d/0B5Z5axE … dnMnc/edit

#11 Re: PDF Engine » Problem with drawing metafile » 2012-11-22 13:03:18

I have one more question. Which approach is better?

1)
  PdfPage.PageWidth := Round(72 * Emf.MMWidth / 2540);
  PdfPage.PageHeight := Round(72 * Emf.MMHeight / 2540);
  PdfDoc.VCLCanvas.StretchDraw(Rect(0, 0, Round(Screen.PixelsPerInch * Emf.MMWidth / 2540), Round(Screen.PixelsPerInch * Emf.MMHeight / 2540)), Emf);

2)

  PdfPage.PageWidth := (72 * Emf.MMWidth) div 2540;
  PdfPage.PageHeight := (72 * Emf.MMHeight) div 2540;
  PdfDoc.VCLCanvas.StretchDraw(Rect(0, 0, (Screen.PixelsPerInch * Emf.MMWidth) div 2540, (Screen.PixelsPerInch * Emf.MMHeight) div 2540), Emf);

It seems that the second. What is your opinion ?

#12 Re: PDF Engine » Problem with drawing metafile » 2012-11-21 15:15:19

Now I used the last version from repository (1.18). Actually the printout looks much better.

#13 Re: PDF Engine » Problem with drawing metafile » 2012-11-21 15:06:08

I used the last stable version (1.15). I try it again with the newer version from repository.

#15 PDF Engine » Problem with drawing metafile » 2012-11-21 13:42:04

cedo
Replies: 7

Hello

We have the following code:

const
  OutputFileName = 'test.pdf';
  InputFileName = 'test.emf';
var
  PdfDoc: TPDFDocumentGDI;
  PdfPage: TPdfpage;
  Emf: TMetafile;
begin
  Emf := TMetafile.Create();
  Emf.LoadFromFile(InputFileName);
 
  PdfDoc := TPdfDocumentGDI.Create;
  PdfDoc.CompressionMethod := cmFlateDecode;
  PdfDoc.DefaultPaperSize := psUserDefined;
  PdfPage := PdfDoc.AddPage();
  PdfPage.PageWidth := Round(72 * Emf.MMWidth / 2540);
  PdfPage.PageHeight := Round(72 * Emf.MMHeight / 2540);
  PdfDoc.VCLCanvas.StretchDraw(Rect(0, 0, Round(Screen.PixelsPerInch * Emf.MMWidth / 2540), Round(Screen.PixelsPerInch * Emf.MMHeight / 2540)), Emf);
  PdfDoc.SaveToFile(OutputFileName);
  PdfDoc.Free();

  FreeAndNil(Emf);
end;

You can download my metafile from here:
https://docs.google.com/open?id=0B5Z5ax … HRVQVVLcWM

The ouput file is blank. The question is: what am I doing wrong?

Board footer

Powered by FluxBB