我有超过1000个图像和视频需要加密。没什么比这更简单的了,我想用AES,但我搞不懂如何在我的电脑上加密,然后在设备上解密。在
我会用python加密我电脑上的所有项目。然后以随需应变的方式用java(Android应用程序)解密物品
任何简单的解释都可以实现伪代码。在
我面临的主要问题是如何使用同一个密钥来加密和解密。我一直在生成密钥,但无法将其传输到另一个设备进行解密。在
谢谢
Python代码。工作加密和解密。在from Crypto.Cipher import AES
import os, random, struct
key = '0123456789abcdef'
mode = AES.MODE_CBC
chunksize = 64*1024
iv = ''.join(chr(random.randint(0,0xFF)) for i in range(16))
encryptor = AES.new(key,mode,iv)
filesize = os.path.getsize('sample.jpg')
with open('sample.jpg','rb') as infile:
with open('sample.enc','wb') as outfile:
outfile.write(struct.pack('
outfile.write(iv)
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += ' ' * (16 - len(chunk) % 16)
outfile.write(encryptor.encrypt(chunk))
## decrypt
with open('sample.enc', 'rb') as infile:
origsize = struct.unpack('
iv = infile.read(16)
decryptor = AES.new(key, AES.MODE_CBC, iv)
with open('sample2.jpg', 'wb') as outfile:
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
outfile.write(decryptor.decrypt(chunk))
outfile.truncate(origsize)
如何在Java中完成解密部分?这是我快速的草率的java代码,它不起作用。我想是填充物把事情搞砸了。在
^{pr2}$