(messageFilename, keyFilename, message, blockSize=DEFAULT_BLOCK_SIZE)
| 87 | |
| 88 | |
| 89 | def encryptAndWriteToFile(messageFilename, keyFilename, message, blockSize=DEFAULT_BLOCK_SIZE): |
| 90 | keySize, n, e = readKeyFile(keyFilename) |
| 91 | if keySize < blockSize * 8: |
| 92 | sys.exit('ERROR: Block size is %s bits and key size is %s bits. The RSA cipher requires the block size to be equal to or greater than the key size. Either decrease the block size or use different keys.' % (blockSize * 8, keySize)) |
| 93 | |
| 94 | encryptedBlocks = encryptMessage(message, (n, e), blockSize) |
| 95 | |
| 96 | for i in range(len(encryptedBlocks)): |
| 97 | encryptedBlocks[i] = str(encryptedBlocks[i]) |
| 98 | encryptedContent = ','.join(encryptedBlocks) |
| 99 | encryptedContent = '%s_%s_%s' % (len(message), blockSize, encryptedContent) |
| 100 | with open(messageFilename, 'w') as fo: |
| 101 | fo.write(encryptedContent) |
| 102 | return encryptedContent |
| 103 | |
| 104 | |
| 105 | def readFromFileAndDecrypt(messageFilename, keyFilename): |
no test coverage detected