Beispiel #1
0
def get_output_size(input_size, encoding='binary'):
    data = Random.get_random_bytes(input_size)
    if encoding.lower() in ['base64', 'b64']:
        cipher_text = Strong(A).enc_base64(data, A)
    else:
        cipher_text = Strong(A).enc(data, A)
    return len(cipher_text)
Beispiel #2
0
 def test_dec_fromself_b64(self):
     data = u'this is a unicode string with chinese for testing the code\n這是中文'.encode(
         'utf-8')
     cipher_text_b64 = Strong(self.A).enc_base64(data, self.A)
     plain_text = Strong(self.A).dec_base64(cipher_text_b64)
     self.assertIsNotNone(plain_text)
     self.assertEqual(data, plain_text)
Beispiel #3
0
def dec(args):
    name = args.identity.read().decode('utf-8')
    args.identity.close()
    plain_text = Strong(name).dec(args.input.read())
    args.input.close()
    args.output.write(plain_text)
    args.output.close()
Beispiel #4
0
def enc(args):
    name = args.identity.read().decode('utf-8')
    args.identity.close()
    cipher_text = Strong(name).enc(args.input.read(), args.recipient)
    args.input.close()
    args.output.write(cipher_text)
    args.output.close()
Beispiel #5
0
 def test_enc_toself_b64(self):
     data = '123'
     cipher_text = Strong(self.A).enc(data, self.A)
     self.assertIsNotNone(cipher_text)
Beispiel #6
0
 def test_pg(self):
     private_keyA = Strong(self.A).privatekey()
     public_keyB = Strong(self.A).publickey(self.B)
     self.assertEqual(private_keyA.p, public_keyB.p)
     self.assertEqual(private_keyA.g, public_keyB.g)
Beispiel #7
0
 def test_read_public(self):
     public_key = Strong(self.A).publickey(self.B)
     self.assertIsNotNone(public_key)
     self.assertIsInstance(public_key, ElGamalobj)
Beispiel #8
0
 def test_read_private(self):
     private_key = Strong(self.A).privatekey()
     self.assertIsNotNone(private_key)
     self.assertIsInstance(private_key, ElGamalobj)
     self.assertTrue(private_key.has_private())