unit deencrypt; {$mode objfpc}{$H+} interface uses Classes, SysUtils; // requires gpg function encrypt(content, recipient: string): string; function decrypt(content: string): string; implementation uses Process, Math; function encrypt(content, recipient: string): string; var p: tProcess; s: string; begin result:=''; p:=tProcess.create(nil); with p do begin executable:='gpg'; parameters.add('-e'); parameters.add('-q'); parameters.add('--batch'); parameters.add('--no-tty'); parameters.add('-r'); parameters.add(recipient); parameters.add('-o'); parameters.add('-'); parameters.add('-'); options:=options + [poUsePipes]; execute; closeStderr; end; while p.running or (p.output.numBytesAvailable>0) do begin if p.output.numBytesAvailable>0 then begin setLength(s,p.output.numBytesAvailable); setLength(s,p.output.read(s[1],length(s))); result:=result+s; continue; end; if content<>'' then begin delete(content,1,p.input.write(content[1],min(128,length(content)))); if content='' then p.closeInput; continue; end; sleep(10); end; p.waitOnExit; p.free; content:=result; result:=''; p:=tProcess.create(nil); with p do begin executable:='base64'; parameters.add('-w'); parameters.add('0'); options:=options + [poUsePipes]; execute; closeStderr; end; while p.running or (p.output.numBytesAvailable>0) do begin if p.output.numBytesAvailable>0 then begin setLength(s,p.output.numBytesAvailable); setLength(s,p.output.read(s[1],length(s))); result:=result+s; continue; end; if content<>'' then begin delete(content,1,p.input.write(content[1],min(128,length(content)))); if content='' then p.closeInput; continue; end; sleep(10); end; p.waitOnExit; p.free; end; function decrypt(content: string): string; var p: tProcess; s: string; begin result:=''; p:=tProcess.create(nil); with p do begin executable:='base64'; parameters.add('-d'); options:=options + [poUsePipes]; execute; closeStderr; end; while p.running or (p.output.numBytesAvailable>0) do begin if p.output.numBytesAvailable>0 then begin setLength(s,p.output.numBytesAvailable); setLength(s,p.output.read(s[1],length(s))); result:=result+s; continue; end; if content<>'' then begin delete(content,1,p.input.write(content[1],min(128,length(content)))); if content='' then p.closeInput; continue; end; sleep(10); end; p.waitOnExit; p.free; content:=result; result:=''; p:=tProcess.create(nil); with p do begin executable:='gpg'; parameters.add('-d'); parameters.add('-q'); parameters.add('--batch'); parameters.add('--no-tty'); parameters.add('-o'); parameters.add('-'); parameters.add('-'); options:=options + [poUsePipes]; execute; closeStderr; end; while p.running or (p.output.numBytesAvailable>0) do begin if p.output.numBytesAvailable>0 then begin setLength(s,p.output.numBytesAvailable); setLength(s,p.output.read(s[1],length(s))); result:=result+s; continue; end; if content<>'' then begin delete(content,1,p.input.write(content[1],min(128,length(content)))); if content='' then p.closeInput; continue; end; sleep(10); end; p.waitOnExit; p.free; end; end.