파워 쉘은 그
-EncodedCommand
파라미터 UTF-16 LE 부호화 문자열을 Base64 인코딩을 받아 들인다.
UTF-16 LE는 [System.Text.Encoding]::Unicode
을 나타내고 두 개의 바이트로 유니 코드 문자 (코드 포인트)의 대부분을 인코딩합니다. VBScript와 PowerShell 모두 내부적으로 문자열 인코딩입니다. 거기
반면
, 대부분의 VBScript 솔루션은 단일 -byte ASCII 인코딩을 사용, 심지어 다른 laudably 유니 코드를 인식 https://www.base64encode.org/ 만 주로 단일 바이트가 UTF-8 기반 인코딩을 (제공 -for-Western-languages 인코딩은 다른 언어의 문자로, 2-4 바이트로 표시됨).
여기에 강력한 UTF-16 LE 기반 Base64 인코딩 솔루션이 있습니다.
선택적으로 지원하는 모듈 식 변형을 게시했습니다. UTF-8here; 두 위치의 코드는 this great answer에 작성됩니다.
예 전화 :
Base64EncodeUtf16Le("(get-date).date") ' -> "KABnAGUAdAAtAGQAYQB0AGUAKQAuAGQAYQB0AGUA"
소스 코드 : 솔루션을 단순화하는 데 도움을위한 MC ND에 모자 팁.
' Base64-encodes the specified string using UTF-16 LE as the underlying text
' encoding.
Function Base64EncodeUtf16Le(ByVal sText)
Dim bytesUtf16Le
' Create an aux. stream from which we can get a binary (byte array)
' representation of the input string in UTF-16 LE encoding.
With CreateObject("ADODB.Stream")
' Create a UTF 16-LE encoded text stream...
.Type = 2 ' adTypeText
.Charset = "utf-16le"
.Open
.WriteText sText
' ... and convert it to a binary stream,
' so we can get the string as a byte array
.Position = 0
.Type = 1 ' adTypeBinary
.Position = 2 ' Skip BOM
bytesUtf16Le = .Read
.Close
End With
' Use an aux. XML document with a Base64-encoded element.
' Assigning a byte stream (array) to .NodeTypedValue
' automatically performs Base64-encoding, whose result can then be accessed
' as the element's text.
With CreateObject("Msxml2.DOMDocument").CreateElement("aux")
.DataType = "bin.base64"
.NodeTypedValue = bytesUtf16Le
Base64EncodeUtf16Le = .Text
End With
End Function
그레이트!나는 시험하고 있었지만'utf-16le' 옵션을 놓쳤습니다. 내 코드를 정보에 적용했지만 의심 스럽습니다 : 왜 두 개의 'adodb.stream' 객체입니까? 하나만있는 솔루션이 실패 할 수있는 경우가 있습니까? 두 개의 인스턴스를 사용하여 개선이 있습니까? –
@MCND D' oh! 고마워, 내 대답을 업데이 트했습니다 - 1 스트림으로 충분합니다; 하나의 스트림을 실험하면서 오래된 코드와 실수를 조합하면 2 개의 스트림이 필요하다는 잘못된 생각이 들게되었습니다. – mklement0