我认为AES256不够强大。如果您知道加密之前预期的字符范围(数字和字母),则应该很容易用蛮力攻击将其解密。我尝试使用部分正确的键,并设法看到了纯文本的某些部分。
最终,我想到了多次加密加密文本的想法。我对随机生成的密钥的要求是包含所有256个ASCII字符。
假设我的密钥是2048个字节。此密钥的每32个字节应加密一个以前加密的文本。这意味着2048/32 = 64次迭代。
我下面的代码基于https://gist.github.com/ctigeek/2a56648b923d198a6e60
答案 0 :(得分:3)
我认为AES256不够强大。
您应该证明这种主张。要强行使用128位密钥,需要花费数年的时间,并在256位密钥的迭代过程中遍历我们的太阳系。到目前为止,AES还没有破裂,您可以相信人们比我们更聪明。尽管这假定密钥具有较高的熵(足够随机)。
如果您知道加密之前预期的字符范围(数字和字母),应该可以通过蛮力攻击轻松解密。
与加密无关。您正在猜测值,并且如果消息空间(短输入消息)有限,则可能以不可忽略的概率猜测它。没办法。
如果您谈论猜测纯文本或密钥材料,则有所不同。即使纯文本是1个字符,如果您的猜测正确与否,正确加密的值也不会显示出来。
当您真正随机地生成密钥时,您将无法猜测。 256位为32字节长。整个问题的关键在于密钥基短而不是随机的(例如从密码生成密钥)。然后,我们只能用盐和一些密钥生成功能(pbkfd2,..)“修补”弱的输入,但这仍然只能解决。
最终,我想到了多次加密加密文本的想法。我对随机生成的密钥的要求是包含所有256个ASCII字符。
如前所述,多次加密并没有对安全性进行任何改进,对密钥提出额外要求甚至可能降低密钥的随机性。
您将拥有256个字节= 2048位密钥(= 8 x 256个密钥)和256个!可能性(远小于2 ^ 2048种可能性的真正随机密钥)。如果AES本身有效,则256位就足够了。如果AES将被破坏,即使8轮(不是真正的随机密钥)也无法帮助您。
我尝试使用部分正确的键,并设法看到了纯文本的某些部分。
然后您进行加密非常错误。即使将密钥关闭1位,您也将无法解密密文的任何部分。
答案 1 :(得分:-1)
$Message = "Place here your passwords or other confidential data."
# Define how many times you want to iterate (encrypt the encrypted content) AES256 cipher
# If it's 64 means that the genrated key will be: 64 * 32 = 2048 bytes long
$AesIterations = 64
# Define your minimum requirement of unique ASCII characters.
# You may never randomly generate unique 256 chars if the iterations are less than 64
$MinUniqueChars = 256
$aesManaged = New-Object "System.Security.Cryptography.AesManaged"
$aesManaged.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aesManaged.Padding = [System.Security.Cryptography.PaddingMode]::Zeros
$aesManaged.BlockSize = 128
$aesManaged.KeySize = 256
$aesManaged.GenerateKey()
[byte[]]$bytes = @()
while (($bytes | Select-Object -Unique).Count -lt $MinUniqueChars) {
[byte[]]$bytes = @()
for ($i=0; $i -lt $AesIterations; $i++) {
$aesManaged.GenerateKey()
$bytes += $aesManaged.Key
}
}
$aesManaged.Dispose()
Write-Host ("`r`n Unique bytes: " + ($bytes | Select-Object -Unique).Count)
Write-Host ("`r`n Key length: " + ($bytes | Measure-Object).Count + " bytes`r`n")
# Create encryption key for later use.
$bytes | Set-Content .\mykey.key -Encoding Byte
# Get the encryption key in Base64 and export in a file.
$Base64Key = [System.Convert]::ToBase64String($bytes)
$Base64Key | Set-Content .\Base64Key.txt -Encoding ASCII -NoNewline -Force
Write-Host " Encryption key in Base64:`r`n"
$Base64Key
$enc = Get-Content .\mykey.key -Encoding Byte
$bytes = [System.Text.Encoding]::UTF8.GetBytes($Message)
for ($i=0; $i -lt (32 * $AesIterations); $i+=32) {
$aesManaged = New-Object "System.Security.Cryptography.AesManaged"
$aesManaged.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aesManaged.Padding = [System.Security.Cryptography.PaddingMode]::Zeros
$aesManaged.BlockSize = 128
$aesManaged.KeySize = 256
$aesManaged.Key = $enc[$i..($i+31)]
$encryptor = $aesManaged.CreateEncryptor()
$encryptedData = $encryptor.TransformFinalBlock($bytes, 0, $bytes.Length)
[byte[]]$bytes = $aesManaged.IV + $encryptedData
$aesManaged.Dispose()
}
# Convert the encrypted message in Base64 and export in a file.
$EncryptedMessageBase64 = [System.Convert]::ToBase64String($bytes)
$EncryptedMessageBase64 | Set-Content .\EncryptedInBase64.txt -Encoding ASCII -NoNewline -Force
Write-Host "`r`n Encrypted message in Base64:`r`n"
$EncryptedMessageBase64
$enc = Get-Content .\mykey.key -Encoding Byte
$bytes = [System.Convert]::FromBase64String($EncryptedMessageBase64)
# Since the last 32 bytes from the key were used for last iteration you have to start with them first.
# The decryption goes backwards from last 32 bytes to the beginning of your key.
for ($i=(32 * $AesIterations) - 1; $i -gt 0; $i-=32) {
$aesManaged = New-Object "System.Security.Cryptography.AesManaged"
$aesManaged.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aesManaged.Padding = [System.Security.Cryptography.PaddingMode]::Zeros
$aesManaged.BlockSize = 128
$aesManaged.KeySize = 256
$aesManaged.Key = $enc[($i-31)..$i]
$aesManaged.IV = $bytes[0..15]
$decryptor = $aesManaged.CreateDecryptor()
$bytes = $decryptor.TransformFinalBlock($bytes, 16, $bytes.Length - 16);
$aesManaged.Dispose()
}
$PlainText = [System.Text.Encoding]::UTF8.GetString($bytes).Trim([char]0)
Write-Host "`r`n Decrypted message after $AesIterations AES256 iterations:`r`n"
$PlainText