PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 4(def md5 (str)
 5  (($ bytes->string/utf-8) (($ md5) (($ string->bytes/utf-8) str))))
 6
 7(def sha1 (data)
 8  (perl subprocess “
 9	use Digest::SHA qw(sha1_hex);
10	sha1_hex(«data»);
11	”))
12
13(def sha224 (data)
14  (perl subprocess “
15	use Digest::SHA qw(sha224_hex);
16	sha224_hex(«data»);
17	”))
18
19(def sha256 (data)
20  (perl subprocess “
21	use Digest::SHA qw(sha256_hex);
22	sha256_hex(«data»);
23	”))
24
25(def sha384 (data)
26  (perl subprocess “
27	use Digest::SHA qw(sha384_hex);
28	sha384_hex(«data»);
29	”))
30
31(def sha512 (data)
32  (perl subprocess “
33	use Digest::SHA qw(sha512_hex);
34	sha512_hex(«data»);
35	”))
36
37(def whirlpool (data)
38  (perl subprocess “
39        use Digest;
40	
41        my $whirlpool = Digest->new( 'Whirlpool' );
42
43	$whirlpool->add(«data»);
44        $whirlpool->hexdigest;
45	”))
46
47; TODO need a more sane return value than a string
48;(def aes-encrypt (key plaintext)
49;  (perl subprocess “
50;	use Crypt::OpenSSL::AES;
51;
52;	my $cipher = new Crypt::OpenSSL::AES(«key»);
53;	
54;	$cipher->encrypt(«plaintext»);
55;	”))
56;
57;(def aes-decrypt (key ciphertext)
58;  (perl subprocess “
59;	use Crypt::OpenSSL::AES;
60;
61;	my $cipher = new Crypt::OpenSSL::AES(«key»);
62;	
63;	$cipher->decrypt(«ciphertext»);
64;	”))