示例#1
0
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
示例#2
0
文件: secret.py 项目: scholarly/kbsum
    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)
示例#3
0
    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)
示例#4
0
def check_pad(text,bs):
    p = enpad(text,bs)
    u = unpad(p,bs)
    assert (len(p)%bs)==0
    assert u == text