1. Dhananjay Nene
  2. pyedpyper

Commits

Dhananjay Nene  committed 49b8f0e

Added simple aes encryption

  • Participants
  • Parent commits e631a2a
  • Branches default

Comments (0)

Files changed (1)

File rnd/initial/pyedpyper.py

View file
  • Ignore whitespace
         if next :
             next.send(val)
 
+@coroutine
+def encrypt(key, type = 'aes', next = None):
+    from Crypto.Cipher import AES
+    padding = 'XXXXXXXXXXXXXXXX'
+    while True :
+        line = (yield)
+        c = None
+        if type == 'aes' :
+            c = AES.new(key,AES.MODE_ECB)
+        
+        if c :
+            pad = len(line) % 16
+            if pad > 0 :
+                pad = 16 - pad
+            line = line + padding[0:pad]
+            val = c.encrypt(line)
+            next.send(val)
 ##############################################################################
 # Sample Usage
 # NOTE: The usage constructs / use case is an entirely arbitrary sequence of
                     digest(
                          next = tracer('Digest')
                     ),
+                    encrypt(
+                        'thisisasecretkey',
+                        next = tracer('Encrypted')
+                    ),
                     tracer('PostJoin')
                 ])
             )