pycrypto アプリケーションを介して Python で OpenPGP を使用してファイルを暗号化しようとしています。ここのコードで提供されているサンプルに従っています: https://github.com/dlitz/pycrypto/blob/master/lib/Crypto/Cipher/CAST.py
だから私はmode.openPGPを使用していますが、公開鍵を使用して何かを暗号化できないようです. 私の公開鍵は、彼らが指定する 16 バイトの制限をはるかに超えています (そして、私が見たどの世代もこの制限を超えています)。指紋 ID など、ここで使用することになっている別の値はありますか?
ファイルの内容を読み取り、キーで暗号化し、送信する新しいファイルに出力しようとしています (両方とも後で削除されます)。私のコードは次のとおりです。
iv = CryptoRandom.new().read(CAST.block_size)
cipher = CAST.new(public_key, CAST.MODE_OPENPGP, iv)
file = open(filename)
contents = ''.join(file.readlines())
encrypted_contents = cipher.encrypt(contents)
encrypted_filename = filename.replace('/tmp/', '/tmp/encrypted')
encrypted_filename = encrypted_filename.replace('.csv', '.asc')
encrypted_file = open(encrypted_filename, 'w')
encrypted_file.write(encrypted_contents)
return encrypted_filename