EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Unicode library not initialized error

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#16056
Posted: 03/15/2011 05:49:35
by Mariusz Rowinski (Basic support level)
Joined: 02/17/2011
Posts: 8

In linux VCL version I got Exception.Message: Unicode library not initialized while executing LoadFromStreamPFX. On Windows everything works perfect.
Compiler is in both cases windows and linux versions FPC 2.4.0

Siplified code:
Code
procedure Sign(FileName:string);
var
   Document: TElPDFDocument;
   PublicKeyHandler: TElPDFPublicKeySecurityHandler;
   Cert: TElX509Certificate;
   CertStorage: TElMemoryCertStorage;
   F,CertF:TFileStream;
   doSave:Boolean;
   Sig : TElPDFSignature;
   Index : integer;
begin
   doSave:=false;
   F:=TFileStream.Create(FileName, fmOpenReadWrite or fmShareDenyWrite);
   Document:=TElPDFDocument.Create(nil);
   PublicKeyHandler:=TElPDFPublicKeySecurityHandler.Create(nil);
   CertStorage:=TElMemoryCertStorage.Create(nil);
   Cert:=TElX509Certificate.Create(nil);
   try
      try
         Document.Open(F);
         try
            if Document.Encrypted then
            begin
               Writeln('Cannot sign');
               Exit;
            end;
            Index := Document.AddSignature;
            Sig := Document.Signatures[Index];
            Sig.Handler := PublicKeyHandler;
            Sig.AuthorName := 'Company';
            Sig.SigningTime := LocalTimeToUTCTime(Now);
            Sig.Reason := 'Securing document';
            Sig.Location:='Katowice, Poland';
            Sig.SignatureName:='electronic sign';
            Sig.ContactInfo:='ul.Asda 23, Katowice';
            Sig.SignatureType := stDocument;
            Sig.Invisible := true;

            CertStorage.Clear;
            PublicKeyHandler.SignatureType := pstPKCS7SHA1;
            CertF := TFileStream.Create('pdf.p12', fmOpenRead or fmShareDenyWrite);
            try
               CertF.Position := 0;
{here error}   Cert.LoadFromStreamPFX(CertF, 'secretpassword',0);
               CertStorage.Add(Cert);
               PublicKeyHandler.CertStorage := CertStorage;
               PublicKeyHandler.CustomName := 'Adobe.PPKMS';
               doSave:=True;
            finally
               FreeAndNil(CertF);
            end;
         finally
            Document.Close(doSave);
         end;
      finally
         FreeAndNil(F);
         FreeAndNil(Document);
         FreeAndNil(PublicKeyHandler);
         FreeAndNil(CertStorage);
         FreeAndNil(Cert);
      end;
   except
      on E:Exception do
      begin
         Writeln(E.Message);
         Exit;
      end
   end;
end;
#16058
Posted: 03/15/2011 05:55:35
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

Please add the SBUnicode reference to the uses clause of your project. This should eliminate the issue.
#16059
Posted: 03/15/2011 05:56:36
by Santiago CastaƱo (Standard support level)
Joined: 04/16/2006
Posts: 155

Hi Mariusz,

I've also encountered that problem, but it's fixed putting SBUnicode in Uses clause of your proyect. Eldos already answered this to me previously and it works.

I quote Eldos here:
Quote

You should reference the SBUnicode unit from your project on non-Windows systems. By adding SBUnicode to your project you are telling SBB to use its own Unicode converter, as Linux-based systems do not provide built-in means for encoding conversions. SBUnicode is vital not only for PKCS12 functionality, but for many other SBB units as well.
#16062
Posted: 03/15/2011 06:08:36
by Mariusz Rowinski (Basic support level)
Joined: 02/17/2011
Posts: 8

Thanks it works :)

Reply

Statistics

Topic viewed 1185 times

Number of guests: 3, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!