예제 #1
0
 def test_blockcipher(self):
     data = "sdfdsddf"
     key = 'abcdabcd'
     c = cipher.new("DES-CBC", key)
     enc = c.update(data) + c.finish()
     # See if padding is added by default
     self.assertEqual(len(enc), 16)
     d = cipher.new("DES-CBC", key, encrypt=False)
     dec = d.update(enc) + d.finish()
     self.assertEqual(data, dec)
예제 #2
0
 def test_variable_keylength(self):
     encryptkey = "abcdefabcdefghtlgvasdgdgsdgdsg"
     data = "asdfsdfsdfsdfsdfsdfsdfsdf"
     iv = "abcdefgh"
     c = cipher.new("bf-ofb", encryptkey, iv=iv)
     ciphertext = c.update(data) + c.finish()
     decryptkey = encryptkey[0:5] + encryptkey[5:]
     d = cipher.new("bf-ofb", decryptkey, encrypt=False, iv=iv)
     deciph = d.update(ciphertext) + d.finish()
     self.assertEqual(deciph, data)
예제 #3
0
 def test_blockcipher(self):
     data=b"sdfdsddf"
     key=b'abcdabcd'
     c=cipher.new("DES-CBC",key)
     enc=c.update(data)+c.finish()
     # See if padding is added by default
     self.assertEqual(len(enc),16)
     d=cipher.new("DES-CBC",key,encrypt=False)
     dec=d.update(enc)+d.finish()
     self.assertEqual(data,dec)
예제 #4
0
 def test_variable_keylength(self):
     encryptkey=b"abcdefabcdefghtlgvasdgdgsdgdsg"
     data=b"asdfsdfsdfsdfsdfsdfsdfsdf"
     iv=b"abcdefgh"
     c=cipher.new("bf-ofb",encryptkey,iv=iv)
     ciphertext=c.update(data)+c.finish()
     decryptkey=encryptkey[0:5]+encryptkey[5:]
     d=cipher.new("bf-ofb",decryptkey,encrypt=False,iv=iv)
     deciph=d.update(ciphertext)+d.finish()
     self.assertEqual(deciph,data)
예제 #5
0
 def test_ofb_cipher(self):
     data = "sdfdsddfxx"
     key = 'abcdabcd'
     iv = 'abcdabcd'
     c = cipher.new("DES-OFB", key, iv=iv)
     enc = c.update(data) + c.finish()
     # See if padding is added by default
     self.assertEqual(len(enc), len(data))
     d = cipher.new("DES-OFB", key, encrypt=False, iv=iv)
     dec = d.update(enc) + d.finish()
     self.assertEqual(data, dec)
예제 #6
0
 def test_ofb_cipher(self):
     data=b"sdfdsddfxx"
     key=b'abcdabcd'
     iv=b'abcdabcd'
     c=cipher.new("DES-OFB",key,iv=iv)
     enc=c.update(data)+c.finish()
     # See if padding is added by default
     self.assertEqual(len(enc),len(data))
     d=cipher.new("DES-OFB",key,encrypt=False,iv=iv)
     dec=d.update(enc)+d.finish()
     self.assertEqual(data,dec)
예제 #7
0
    def test_ofb_noiv(self):
        data = "sdfdsddfxx"
        encryptkey = 'abcdabcd' * 4
        decryptkey = encryptkey[0:5] + encryptkey[5:]

        c = cipher.new("AES-256-OFB", encryptkey)
        enc = c.update(data) + c.finish()
        # See if padding is added by default
        self.assertEqual(len(enc), len(data))
        d = cipher.new("AES-256-OFB", decryptkey, encrypt=False)
        dec = d.update(enc) + d.finish()
        self.assertEqual(data, dec)
예제 #8
0
    def test_ofb_noiv(self):
        data = "sdfdsddfxx"
        encryptkey = "abcdabcd" * 4
        decryptkey = encryptkey[0:5] + encryptkey[5:]

        c = cipher.new("AES-256-OFB", encryptkey)
        enc = c.update(data) + c.finish()
        # See if padding is added by default
        self.assertEqual(len(enc), len(data))
        d = cipher.new("AES-256-OFB", decryptkey, encrypt=False)
        dec = d.update(enc) + d.finish()
        self.assertEqual(data, dec)
예제 #9
0
 def test_blockcipher_nopadding(self):
     data = "sdfdsddf"
     key = "abcdabcd"
     c = cipher.new("DES-CBC", key)
     c.padding(False)
     enc = c.update(data) + c.finish()
     # See if padding is added by default
     self.assertEqual(len(enc), 8)
     d = cipher.new("DES-CBC", key, encrypt=False)
     d.padding(False)
     dec = d.update(enc) + d.finish()
     self.assertEqual(data, dec)
예제 #10
0
 def test_wrong_ivlength(self):
     key = "abcdabcdabcdabcd"
     iv = "xxxxx"
     with self.assertRaises(ValueError):
         c = cipher.new("AES-128-OFB", key, iv=iv)
예제 #11
0
 def test_wrong_keylength(self):
     data = "sdfsdfxxx"
     key = "abcdabcd"
     with self.assertRaises(ValueError):
         c = cipher.new("AES-128-OFB", key)
예제 #12
0
 def test_wrong_ivlength(self):
     key=b"abcdabcdabcdabcd"
     iv=b"xxxxx"
     with self.assertRaises(ValueError):
         c=cipher.new("AES-128-OFB",key,iv=iv)
예제 #13
0
 def test_wrong_keylength(self):
     data=b"sdfsdfxxx"
     key=b"abcdabcd"
     with self.assertRaises(ValueError):
         c=cipher.new("AES-128-OFB",key)