Powershell百科全书和Python解密

Powershell百科全书和Python解密,python,powershell,encryption,aes,Python,Powershell,Encryption,Aes,我有一个即将退役的数据库,但它存储“机密”,我需要能够加密数据并保存到windows计算机,然后在linux计算机上解密 我已经在powershell中完成了加密,但是,我不知道我是否正在将encyption密钥和初始化向量正确地输入python,因为它没有被正确地解密 以下是用于读取明文密码并对其进行加密的powershell代码: $key = New-Object Byte[] 32 [Security.Cryptography.RNGCryptoServiceProvider]::Cre

我有一个即将退役的数据库,但它存储“机密”,我需要能够加密数据并保存到windows计算机,然后在linux计算机上解密

我已经在powershell中完成了加密,但是,我不知道我是否正在将encyption密钥和初始化向量正确地输入python,因为它没有被正确地解密

以下是用于读取明文密码并对其进行加密的powershell代码:

$key = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($key)

$AES = New-Object System.Security.Cryptography.AesManaged
$iv = $AES.IV
$key = $AES.Key

$iv | Out-File IV.key
$key | Out-File AES.key 

$raw = Get-Content -Path .\passwords.txt -Raw

foreach ($line in -split $raw) {
    $secure_pass = ConvertTo-SecureString -String $line -AsPlainText -Force
    $encrypted_pass = ConvertFrom-SecureString -SecureString $secure_pass -key $key 
    $encrypted_pass | Add-Content encrypted_passes.txt
}
这是python中的解密代码:

rom Crypto import Random
from Crypto.Cipher import AES


key = open("AES.key","r")
iv = open("IV2.key","r")
password_file = open("encrypted_passes.txt","r")
iv_text = iv.read()
key_text = key.read()
iv_base = base64.b64encode(iv_text)
print "IV: " + iv_base[:16]
base_key = base64.b64encode(key_text)
aes = AES.new(base_key[:32], AES.MODE_CBC, iv_base[:16])
print len(iv_base)

for line in password_file:
        print line
        print "blah: " + aes.decrypt(line[:32])
我希望python能够读取加密的密码文件,并能够正确解密它