def testF02EncryptPublicArmor(self): "encrypt_str()/decrypt_str() ElGamal via user ID (armored)" pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc']) seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc']) cphtxt = encrypt_str(self.lit_data,keys=pubkey_d, use_userid=[(None,"Tester")], armor=True) self.assertEqual(True, looks_armored(cphtxt))
def testF03EncryptPublicKeyID(self): "encrypt_str()/decrypt_str() ElGamal via key ID" pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc']) seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc']) cphtxt = encrypt_str(self.lit_data, keys=pubkey_d, use_key=[(None,"CB7D6980A1F2BEF6")]) clrtxt = decrypt_str(cphtxt, passphrase="test", keys=seckey_d, decompress=True) litmsg = list_as_signed(clrtxt)[0] # auto-decompressed above self.assertEqual(self.lit_data, litmsg.literals[0].body.data)
def testF02EncryptPublicArmor(self): "encrypt_str()/decrypt_str() ElGamal via user ID (armored)" pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc']) seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc']) cphtxt = encrypt_str(self.lit_data, keys=pubkey_d, use_userid=[(None, "Tester")], armor=True) self.assertEqual(True, looks_armored(cphtxt))
def testF04EncryptPublicKeyIDNoTarget(self): "encrypt_str()/decrypt_str() no specified encryption key" pubkey_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc']) seckey_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc']) try: cphtxt = encrypt_str(self.lit_data, keys=pubkey_d) # missing target except PGPError: pass else: self.fail()
def testF04EncryptPublicKeyIDNoTarget(self): "encrypt_str()/decrypt_str() no specified encryption key" pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc']) seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc']) try: cphtxt = encrypt_str(self.lit_data, keys=pubkey_d) # missing target except PGPError: pass else: self.fail()
def testF03EncryptPublicKeyID(self): "encrypt_str()/decrypt_str() ElGamal via key ID" pubkey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc']) seckey_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc']) cphtxt = encrypt_str(self.lit_data, keys=pubkey_d, use_key=[(None, "CB7D6980A1F2BEF6")]) clrtxt = decrypt_str(cphtxt, passphrase="test", keys=seckey_d, decompress=True) litmsg = list_as_signed(clrtxt)[0] # auto-decompressed above self.assertEqual(self.lit_data, litmsg.literals[0].body.data)
def testF06EncryptMultiplePublicUserID(self): "encrypt_str()/decrypt_str() multiple public (no compression) via user ID" pubkey1_d = read_test_file(['pgpfiles','key','DSAELG1.pub.asc']) seckey1_d = read_test_file(['pgpfiles','key','DSAELG1.sec.asc']) #pubkey2_d = read_test_file(['pgpfiles','key','DSAELG3.pub.asc']) #seckey2_d = read_test_file(['pgpfiles','key','DSAELG3.sec.asc']) pubkey3_d = read_test_file(['pgpfiles','key','RSA1.pub.asc']) seckey3_d = read_test_file(['pgpfiles','key','RSA1.sec.asc']) pubkey_d = linesep.join([pubkey1_d, pubkey3_d]) uids = [(None,"Tester"), #(None,"*****@*****.**"), (None,"testrsa")] cphtxt = encrypt_str(self.lit_data, keys=pubkey_d, use_userid=uids) # they all happen to have the same passphrase passphrase = "test" for seckey_d in [seckey1_d, seckey3_d]: clrtxt = decrypt_str(cphtxt, passphrase="test", keys=seckey_d, decompress=True) litmsg = list_as_signed(clrtxt)[0] self.assertEqual(self.lit_data, litmsg.literals[0].body.data)
def testF06EncryptMultiplePublicUserID(self): "encrypt_str()/decrypt_str() multiple public (no compression) via user ID" pubkey1_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.pub.asc']) seckey1_d = read_test_file(['pgpfiles', 'key', 'DSAELG1.sec.asc']) #pubkey2_d = read_test_file(['pgpfiles','key','DSAELG3.pub.asc']) #seckey2_d = read_test_file(['pgpfiles','key','DSAELG3.sec.asc']) pubkey3_d = read_test_file(['pgpfiles', 'key', 'RSA1.pub.asc']) seckey3_d = read_test_file(['pgpfiles', 'key', 'RSA1.sec.asc']) pubkey_d = linesep.join([pubkey1_d, pubkey3_d]) uids = [ (None, "Tester"), #(None,"*****@*****.**"), (None, "testrsa") ] cphtxt = encrypt_str(self.lit_data, keys=pubkey_d, use_userid=uids) # they all happen to have the same passphrase passphrase = "test" for seckey_d in [seckey1_d, seckey3_d]: clrtxt = decrypt_str(cphtxt, passphrase="test", keys=seckey_d, decompress=True) litmsg = list_as_signed(clrtxt)[0] self.assertEqual(self.lit_data, litmsg.literals[0].body.data)
def testF05EncryptSymmetric(self): "encrypt_str()/decrypt_str() symmetric default" cphtxt = encrypt_str(self.lit_data, passphrase="test") clrtxt = decrypt_str(cphtxt, passphrase="test", decompress=True) litmsg = list_as_signed(clrtxt)[0] # auto-decompressed above self.assertEqual(self.lit_data, litmsg.literals[0].body.data)