You are not logged in.
Pages: 1
I confirm it was that (the IVAtBeginning parameter). Thanks.
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 ?
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 ?
I think of non-printable warterwarks, text or graphics (an advertisement). And what about comments and annotations ? How can I use comments and annotations ?
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 ?
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 ?
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.
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.
I don't know what you mean.
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
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 ?
Now I used the last version from repository (1.18). Actually the printout looks much better.
I used the last stable version (1.15). I try it again with the newer version from repository.
Something is wrong. The output file is bad:
https://docs.google.com/open?id=0B5Z5ax … VBaa1ZCU1E
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?
Pages: 1