/lib/crypto.arc

http://github.com/alimoeeny/arc · Unknown · 64 lines · 54 code · 10 blank · 0 comment · 0 complexity · fbb46bb416a436570193d45904791db3 MD5 · raw file

  1. ($ (require file/md5))
  2. (load "lib/lang.arc")
  3. (def md5 (str)
  4. (($ bytes->string/utf-8) (($ md5) (($ string->bytes/utf-8) str))))
  5. (def sha1 (data)
  6. (perl subprocess
  7. use Digest::SHA qw(sha1_hex);
  8. sha1_hex(«data»);
  9. ))
  10. (def sha224 (data)
  11. (perl subprocess
  12. use Digest::SHA qw(sha224_hex);
  13. sha224_hex(«data»);
  14. ))
  15. (def sha256 (data)
  16. (perl subprocess
  17. use Digest::SHA qw(sha256_hex);
  18. sha256_hex(«data»);
  19. ))
  20. (def sha384 (data)
  21. (perl subprocess
  22. use Digest::SHA qw(sha384_hex);
  23. sha384_hex(«data»);
  24. ))
  25. (def sha512 (data)
  26. (perl subprocess
  27. use Digest::SHA qw(sha512_hex);
  28. sha512_hex(«data»);
  29. ))
  30. (def whirlpool (data)
  31. (perl subprocess
  32. use Digest;
  33. my $whirlpool = Digest->new( 'Whirlpool' );
  34. $whirlpool->add(«data»);
  35. $whirlpool->hexdigest;
  36. ))
  37. ; TODO need a more sane return value than a string
  38. ;(def aes-encrypt (key plaintext)
  39. ; (perl subprocess
  40. ; use Crypt::OpenSSL::AES;
  41. ;
  42. ; my $cipher = new Crypt::OpenSSL::AES(«key»);
  43. ;
  44. ; $cipher->encrypt(«plaintext»);
  45. ; ))
  46. ;
  47. ;(def aes-decrypt (key ciphertext)
  48. ; (perl subprocess
  49. ; use Crypt::OpenSSL::AES;
  50. ;
  51. ; my $cipher = new Crypt::OpenSSL::AES(«key»);
  52. ;
  53. ; $cipher->decrypt(«ciphertext»);
  54. ; ))