크롬이든 Powerherll이든 Openssl equivalent의 AES를 사용할 수 있습니다
36534 단어 ChromeJavaScriptPowerShelltech
가져오기
encrypt
우선 CLI
echo "message" | openssl enc -aes-256-cbc -a -pbkdf2 -md sha512 -p -pass pass:hoge
javascript(chrome에서만 확인)로 이 등가의 일을 합니다. c={text:"message",algenc:"AES-CBC",algbit:256,algkd:"pbkdf2",alghash:"SHA-512",kdi:10000,c:crypto,u:Uint8Array,e:x=>(new TextEncoder()).encode(x)};
c.passbin=(new TextEncoder()).encode("hoge");
c.salt=c.c.getRandomValues(new c.u(8))
c.c.subtle.importKey("raw",c.passbin,{name:c.algkd},!1,["deriveBits"])
.then(km => c.c.subtle.deriveBits( { name: c.algkd, salt: c.salt, iterations: c.kdi, hash: c.alghash }, km, 8*(32+16) )) // key(32)+iv(16)
.then(b => (c.db=b)&&(c.iv=b.slice(32,48))&&c.c.subtle.importKey("raw",b.slice(0,32),c.algenc,!1,["encrypt"]))
.then(k => (c.key=k)&&c.c.subtle.encrypt({name:c.algenc,iv:c.iv},c.key,c.e(c.text)))
.then(e=>c.encrypted=window.btoa(String.fromCharCode(...([...c.e("Salted__"),...c.salt,...(new c.u(e))]))))
.finally(()=>console.log(c.encrypted))
파워힐도 합니다. function enc($s, $p){
$salt = New-Object byte[] 8
$rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
$rng.getBytes($salt)
$kiv = (New-Object System.Security.Cryptography.Rfc2898DeriveBytes([System.Text.Encoding]::UTF8.GetBytes($p), $salt, 10000, [System.Security.Cryptography.HashAlgorithmName]::SHA512)).GetBytes(48)
$aes = New-Object System.Security.Cryptography.AesManaged
$aes.KeySize = 256
$aes.BlockSize = 128
$aes.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aes.Padding = [System.Security.Cryptography.PaddingMode]::PKCS7
$aes.Key = $kiv[0..31]
$aes.IV = $kiv[32..47]
$encryptor = $aes.CreateEncryptor($aes.Key, $aes.IV)
$bytes = [System.Text.Encoding]::UTF8.GetBytes($s)
$ms = [System.IO.MemoryStream]::new()
$ms.Write([System.Text.Encoding]::UTF8.GetBytes("Salted__") + $salt, 0, 16)
$cs = New-Object System.Security.Cryptography.CryptoStream($ms, $encryptor, [System.Security.Cryptography.CryptoStreamMode]::Write)
$cs.Write($bytes, 0, $bytes.length)
$cs.FlushFinalBlock()
$cs.Close()
[System.Convert]::ToBase64String($ms.ToArray())
$ms.Close()
$encryptor.Dispose()
$aes.Dispose()
}
enc "message" "hoge"
decrypt
그리고 cli에서 decrype.
echo "U2FsdGVkX1+6SGosjqp5QKdNOwVIn5KAvOQtTqObCAE=" | openssl enc -aes-256-cbc -a -d -pbkdf2 -md sha512 -p -pass pass:hoge
등효javascript c={enctext:"U2FsdGVkX1+6SGosjqp5QKdNOwVIn5KAvOQtTqObCAE=",algenc:"AES-CBC",algbit:256,algkd:"pbkdf2",alghash:"SHA-512",kdi:10000,c:crypto,u:Uint8Array};
c.passbin=(new TextEncoder()).encode("hoge");
c.encbin=new c.u(window.atob(c.enctext).split("").map(a=>a.charCodeAt(0)));
c.salt=c.encbin.slice(8,16);
c.c.subtle.importKey("raw",c.passbin,{name:c.algkd},!1,["deriveBits"])
.then(km => c.c.subtle.deriveBits( { name: c.algkd, salt: c.salt, iterations: c.kdi, hash: c.alghash }, km, 8*(32+16)) ) // key(32)+iv(16)
.then(b => (c.db=b)&&(c.iv=b.slice(32,48))&&c.c.subtle.importKey("raw",b.slice(0,32),c.algenc,!1,["decrypt"]))
.then(k => (c.key=k)&&c.c.subtle.decrypt({name:c.algenc,iv:c.iv},c.key,c.encbin.slice(16)))
.then(d=>c.decodedtext=(new TextDecoder("utf-8")).decode(new c.u(d)))
.finally(()=>console.log(c.decodedtext))
powershell function dec($s, $p){ # base64str
$encText = [System.Convert]::FromBase64String($s);
$salt = $encText[8..15]
$kiv = (New-Object System.Security.Cryptography.Rfc2898DeriveBytes([System.Text.Encoding]::UTF8.GetBytes($p), $salt, 10000, [System.Security.Cryptography.HashAlgorithmName]::SHA512)).GetBytes(48)
$aes = New-Object System.Security.Cryptography.AesManaged
$aes.KeySize = 256
$aes.BlockSize = 128
$aes.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aes.Padding = [System.Security.Cryptography.PaddingMode]::PKCS7
$aes.Key = $kiv[0..31]
$aes.IV = $kiv[32..47]
$decryptor = $aes.CreateDecryptor()
$ms1 = [System.IO.MemoryStream]::new($encText[16..($encText.Length-1)])
$cs = New-Object System.Security.Cryptography.CryptoStream($ms1, $decryptor, [System.Security.Cryptography.CryptoStreamMode]::Read)
$ms2 = [System.IO.MemoryStream]::new()
$cs.CopyTo($ms2)
$ms1.Close()
$ms2.Close()
$cs.Close()
[System.Text.Encoding]::UTF8.GetString($ms2.ToArray())
$decryptor.Dispose()
$aes.Dispose()
}
dec "U2FsdGVkX1+6SGosjqp5QKdNOwVIn5KAvOQtTqObCAE=" "hoge"
배우다
Salted__
라는 문자열과 염량값(8bytes)Reference
이 문제에 관하여(크롬이든 Powerherll이든 Openssl equivalent의 AES를 사용할 수 있습니다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/nabesgo/articles/openssl-javascript-powershell텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)