def urlsafe_encrypt(key, plaintext, blocksize=16):
 def pad(text):
  '\n        Pads text to be encrypted\n        '
  pad_length = (blocksize - (len(text) % blocksize))
  sr = random.StrongRandom()
  pad = ''.join((six.int2byte(sr.randint(1, 255)) for i in range((pad_length - 1))))
  return ((text + '\x00') + pad)
 plaintext = encodeutils.to_utf8(plaintext)
 key = encodeutils.to_utf8(key)
 init_vector = Random.get_random_bytes(16)
 cypher = AES.new(key, AES.MODE_CBC, init_vector)
 padded = cypher.encrypt(pad(six.binary_type(plaintext)))
 encoded = base64.urlsafe_b64encode((init_vector + padded))
 if six.PY3:
  encoded = encoded.decode('ascii')
 return encoded

def urlsafe_encrypt ( key , plaintext , blocksize = 16 ) : def pad ( text ) : pad_length = ( blocksize - ( len ( text ) % blocksize ) ) sr = random . StrongRandom ( ) pad = '' . join ( ( six . int2byte ( sr . randint ( 1 , 255 ) ) for i in range ( ( pad_length - 1 ) ) ) ) return ( ( text + '\x00' ) + pad ) plaintext = encodeutils . to_utf8 ( plaintext ) key = encodeutils . to_utf8 ( key ) init_vector = Random . get_random_bytes ( 16 ) cypher = AES . new ( key , AES . MODE_CBC , init_vector ) padded = cypher . encrypt ( pad ( six . binary_type ( plaintext ) ) ) encoded = base64 . urlsafe_b64encode ( ( init_vector + padded ) ) if six . PY3 : encoded = encoded . decode ( 'ascii' ) return encoded
encrypts plaintext .