def test_double(): a = b"hello" b = enpad(a,16) c = enpad(b,16) d = unpad(c,16) assert b==d e = unpad(d,16) assert a==e
def encrypt(self,plaintext,nonce): if len(nonce)!=self.NONCE_SIZE: raise ValueError("nonce must be exactly {0:d} bytes long (not {1:d})" .format(self.NONCE_SIZE,len(nonce))) c = self._cipher.new(self.__key,self._cipher.MODE_CBC,nonce) ct = c.encrypt(enpad(plaintext,c.block_size)) return nonce+ct+self._getmac(nonce,ct)
def encrypt(self, plaintext, nonce): if len(nonce) != self.NONCE_SIZE: raise ValueError( "nonce must be exactly {0:d} bytes long (not {1:d})".format( self.NONCE_SIZE, len(nonce))) c = self._cipher.new(self.__key, self._cipher.MODE_CBC, nonce) ct = c.encrypt(enpad(plaintext, c.block_size)) return nonce + ct + self._getmac(nonce, ct)
def check_pad(text,bs): p = enpad(text,bs) u = unpad(p,bs) assert (len(p)%bs)==0 assert u == text