Pastey Crypt/Decrypt

-----------------------------------------------------
-- # Encrypt/Decrypt 
----------------------------------------------------- 
 
include GtkEngine.e 
include std/io.e 
 
uses("ccrypt")  
 
constant 
	win = create(GtkWindow,"size=300x-1;border=10;$destroy=Quit"), 
	pan = create(GtkBox,"orientation=vertical;spacing=5"), 
	lb1 = create(GtkLabel,"Input File"), 
	inp = create(GtkFileChooserButton,"name=input;$file-set=Update"), 
	lb2 = create(GtkLabel,"Output File"), 
	out = create(GtkEntry,"name=output"), 
	lb3 = create(GtkLabel,"Encryption Key"), 
	key = create(GtkEntry,"name=key"), 
	scr = create(GtkScrolledWindow), 
	tv  = create(GtkTextView), buf = get(tv,"buffer"), 
	mode = create(GtkCheckButton,"label=View decoded output;name=mode"), 
	box = create(GtkButtonBox), 
	btn1 = create(GtkButton,"gtk-quit","Quit"), 
	btn2 = create(GtkButton,"stock_lock-ok#_Encrypt","Encrypt"), 
	btn3 = create(GtkButton,"channel-insecure-symbolic#_Decrypt","Decrypt") 
 
set(inp,"action",GTK_FILE_CHOOSER_ACTION_OPEN) 
set(out,"action",GTK_FILE_CHOOSER_ACTION_SAVE)	 
set(btn2,"tooltip text","Encrypt input file") 
set(btn3,"tooltip text","Decrypt input file") 
	 
add(win,pan) 
add(scr,tv) 
add(pan,{lb1,inp,lb2,out,lb3,key,mode}) 
pack(pan,scr,1,1) 
add(box,{btn1,btn2,btn3}) 
pack(pan,-box) 
 
show_all(win) 
main() 
 
------------------------ 
global function Update() 
------------------------ 
set("output.text","") 
return 1 
end function 
 
------------------------- 
global function Encrypt() 
------------------------- 
object inputfile = get("input.filename") 
object outputfile = get("output.text") 
object tempfile = temp_file(canonical_path("~/tmp")) 
object key = get("key.text") 
sequence data 
 
if length(outputfile) > 0 then 
  tempfile = temp_file(canonical_path("~/tmp"),filename(outputfile)) 
end if 
 
if file_exists(inputfile) then 
   data = read_file(inputfile) 
   write_file(tempfile,data) -- copy then encrypt it: 
   if system_exec(format("ccrypt -e -K [] []",{key,tempfile})) != 0 then 
	Warn(,,"Encryption failed!",inputfile) 
   else 
	set("output.text",tempfile) 
   end if 
else 
   Warn(,,"Invalid input file!",inputfile) 
end if 
 
return 1 
end function 
 
------------------------- 
global function Decrypt() 
------------------------- 
object inputfile = get("input.filename")  
object outputfile = get("output.text") 
object key = get("key.text") 
sequence data 
integer x 
 
if not file_exists(inputfile) then  
   return Warn(,,"Invalid encrypted file!",inputfile) 
end if 
 
if length(outputfile) > 0 then 
  x = system_exec(format("ccrypt -c -K [] [] > []",{key,inputfile,outputfile})) 
else 
  x = system_exec(format("ccrypt -d -f -K [] []",{key,inputfile})) 
end if 
 
if x != 0 then  
  return Warn(,,"Decryption failed!",inputfile)  
end if 
   
if get("mode.active") then 
   if file_exists(outputfile) then 
      set(buf,"text",read_file(outputfile)) 
      system_exec(format("ccrypt -e -K [] []",{key,outputfile})) 
   else 
      x  = match(".cpt",inputfile) 
      if x > 0 then 
	inputfile = inputfile[1..x-1] 
      end if 
      set(buf,"text",read_file(inputfile)) 
      system_exec(format("ccrypt -e -K [] []",{key,inputfile})) 
   end if 
end if 
 
return 1 
end function 
 

1. Comment by irv 2 months ago

/*

  • This utility encrypts and decrypts files of any type. The files are encrypted to
  • your /tmp folder with numeric names, for example: 1667834._T_.cpt
  • The encrypted files will all be shown as binary mime type, and won't be viewable.
  • *
  • After you have encrypted one or more files, you can move them to
  • another place for storage.
  • *
  • Don't forget the password!
  • *
  • If you wish to "tag" a file, for example, files belonging to "Julie",
  • then enter "Julie" into the Output File box before encrypting. Then the file
  • will be saved with a name like Julie904829._T_.cpt
  • *
  • To decrypt, select a .cpt file, enter the password, and click the Decrypt button.
  • The file name will lose the .cpt extension, and will be viewable with the usual
  • utilities.
  • *
  • If you wish the decripted file to be renamed and put in another folder,
  • specify the folder and/or name in the Output File box before decrypting,
  • for example: /demos/julie
  • *
  • For text (a list of passwords or phone numbers for example), click on the
  • View decoded output checkbox. The text will appear in the window, but the
  • encrypted file won't be decrypted in the /tmp folder.
  • *
  • Oh, BTW, Don't forget the password!
  • /

2. Comment by irv 2 months ago

If you want the password to be visible as * , add visibility=0: out=create(GtkEntry,"name=key;visibility=0"):

Search



Quick Links

User menu

Not signed in.

Help Fund OpenEuphoria

Misc Menu