def testI01EncryptPublicElGamalDES3ZIP(self): """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity, & ZIP""" key_d = read_test_file(['pgpfiles', 'key', 'DSAELG3.pub.gpg']) keypkt = list_pkts(key_d)[3] # ElGamal encrypting key d = "My secret message." # literal data packet litbody = create_LiteralDataBody(data=d, modified=0, format='b', filename='outfile') litpkt = create_Packet(PKT_LITERAL, litbody._d) # compressed data packet compbody = create_CompressedDataBody(COMP_ZIP, litpkt.rawstr()) comppkt = create_Packet(PKT_COMPRESSED, compbody._d) # session key key = gen_random(_keysize(SYM_DES3)) sespkt = encrypt_public_session(keypkt, key, SYM_DES3) # encrypted data encpkt = encrypt_integrity(SYM_DES3, key, comppkt.rawstr()) # decryption seckey_d = read_test_file( ['pgpfiles', 'key', 'DSAELG3.sec.nopass.gpg']) seckeypkt = list_pkts(seckey_d)[2] clrtxt = decrypt(encpkt, None, sespkt, seckeypkt) # got compressed comppkt_out = list_pkts(clrtxt)[0] # got literal litpkt_out = list_pkts(comppkt_out.body.data)[0] self.assertEqual(d, litpkt_out.body.data) self.assertEqual('outfile', litpkt_out.body.filename) self.assertEqual(0, litpkt_out.body.modified) self.assertEqual('b', litpkt_out.body.format)
def testI01EncryptPublicElGamalDES3ZIP(self): """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity, & ZIP""" key_d = read_test_file(['pgpfiles','key','DSAELG3.pub.gpg']) keypkt = list_pkts(key_d)[3] # ElGamal encrypting key d = "My secret message." # literal data packet litbody = create_LiteralDataBody(data=d, modified=0, format='b', filename='outfile') litpkt = create_Packet(PKT_LITERAL, litbody._d) # compressed data packet compbody = create_CompressedDataBody(COMP_ZIP, litpkt.rawstr()) comppkt = create_Packet(PKT_COMPRESSED, compbody._d) # session key key = gen_random(_keysize(SYM_DES3)) sespkt = encrypt_public_session(keypkt, key, SYM_DES3) # encrypted data encpkt = encrypt_integrity(SYM_DES3, key, comppkt.rawstr()) # decryption seckey_d = read_test_file(['pgpfiles','key','DSAELG3.sec.nopass.gpg']) seckeypkt = list_pkts(seckey_d)[2] clrtxt = decrypt(encpkt, None, sespkt, seckeypkt) # got compressed comppkt_out = list_pkts(clrtxt)[0] # got literal litpkt_out = list_pkts(comppkt_out.body.data)[0] self.assertEqual(d, litpkt_out.body.data) self.assertEqual('outfile', litpkt_out.body.filename) self.assertEqual(0, litpkt_out.body.modified) self.assertEqual('b', litpkt_out.body.format)
def testH01EncryptPublicElGamalDES3(self): """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity""" key_d = read_test_file(['pgpfiles','key','DSAELG3.pub.gpg']) keypkt = list_pkts(key_d)[3] # ElGamal encrypting key msg = "My secret message." key = gen_random(_keysize(SYM_DES3)) sespkt = encrypt_public_session(keypkt, key, SYM_DES3) encpkt = encrypt_integrity(SYM_DES3, key, msg) seckey_d = read_test_file(['pgpfiles','key','DSAELG3.sec.nopass.gpg']) seckeypkt = list_pkts(seckey_d)[2] clrtxt = decrypt(encpkt, None, sespkt, seckeypkt) self.assertEqual(msg, clrtxt)
def testH01EncryptPublicElGamalDES3(self): """crypto.cipher: encrypt()/decrypt() ElGamal, DES3 w/ integrity""" key_d = read_test_file(['pgpfiles', 'key', 'DSAELG3.pub.gpg']) keypkt = list_pkts(key_d)[3] # ElGamal encrypting key msg = "My secret message." key = gen_random(_keysize(SYM_DES3)) sespkt = encrypt_public_session(keypkt, key, SYM_DES3) encpkt = encrypt_integrity(SYM_DES3, key, msg) seckey_d = read_test_file( ['pgpfiles', 'key', 'DSAELG3.sec.nopass.gpg']) seckeypkt = list_pkts(seckey_d)[2] clrtxt = decrypt(encpkt, None, sespkt, seckeypkt) self.assertEqual(msg, clrtxt)
def testH02EncryptPublicRSAAES256(self): """crypto.cipher: encrypt()/decrypt() RSA, AES256 w/ integrity""" key_d = read_test_file(['pgpfiles', 'key', 'RSA1.pub.gpg']) keypkt = list_pkts(key_d)[0] # use RSA for encrypting alg = SYM_AES256 msg = "My secret message." passphrase = 'test' key = gen_random(_keysize(alg)) sespkt = encrypt_public_session(keypkt, key, alg) encpkt = encrypt_integrity(alg, key, msg) seckey_d = read_test_file(['pgpfiles', 'key', 'RSA1.sec.gpg']) seckeypkt = list_pkts(seckey_d)[0] clrtxt = decrypt(encpkt, passphrase, sespkt, seckeypkt) self.assertEqual(msg, clrtxt)
def testH02EncryptPublicRSAAES256(self): """crypto.cipher: encrypt()/decrypt() RSA, AES256 w/ integrity""" key_d = read_test_file(['pgpfiles','key','RSA1.pub.gpg']) keypkt = list_pkts(key_d)[0] # use RSA for encrypting alg = SYM_AES256 msg = "My secret message." passphrase = 'test' key = gen_random(_keysize(alg)) sespkt = encrypt_public_session(keypkt, key, alg) encpkt = encrypt_integrity(alg, key, msg) seckey_d = read_test_file(['pgpfiles','key','RSA1.sec.gpg']) seckeypkt = list_pkts(seckey_d)[0] clrtxt = decrypt(encpkt, passphrase, sespkt, seckeypkt) self.assertEqual(msg, clrtxt)