×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Xojo
Posted by: Radium Kymist
Added: Feb 7, 2015 1:03 PM
Modified: Feb 7, 2015 1:03 PM
Views: 30
Tags: encryption
by simulanics


Requirements:
OpenSSL (included in most OS's)

How to use:
Encrypt: aes_256_cbc("encrypt", string_to_encrypt, password)
Decrypt: aes_256_cbc("decrypt", string_to_decrypt, password)
  1. Function aes_256_cbc(enc_mode as String, str_in as String, secr_key as String) As String
  2.   Dim sh as New Shell
  3.   Dim s as String
  4.  
  5.   if enc_mode = "encrypt" then
  6.     sh.Execute("echo -n " + chr(34) + str_in + chr(34) + " | openssl enc  -aes-256-cbc  -a -pass pass:" + Lowercase(EncodeHex(MD5(secr_key))))
  7.     s = sh.Result
  8.     sh.close
  9.     Return DefineEncoding(s, Encodings.UTF8)
  10.   end if
  11.  
  12.   if enc_mode = "decrypt" then
  13.     sh.Execute("echo " + chr(34) + str_in + chr(34) + " | openssl enc  -aes-256-cbc -a -d -pass pass:" + Lowercase(EncodeHex(MD5(secr_key))))
  14.     s = sh.Result
  15.     sh.close
  16.     Return DefineEncoding(s, Encodings.UTF8)
  17.   end if
  18.         End Function