Apparently the .Net Framework can't do it that way is what I meant. It looks like you're on the right track. Here I use the cmdlet Get-Content to get the content of the current problematic file (norwegian-vowels.txt), pipe it to Set-Content with the parameter -Encoding utf8 and a new file name as the output file (norwegian-vowels-utf8.txt). Then I just pass it to Import-Csv to verify it's displayed correctly. What's the easiest way to convert XML from UTF16 to a UTF8 encoded file? Bytes != Base64. The code in my example produces exactly the output you want.Except in this case it appears that the api requires an encoded byte array and not just a byte array.I'm not sure what you mean by "the api", but a byte array is not aware of any encoding. Ask Question Asked 11 years, 3 months ago. The command you are looking for is Set-Content. I tried repeatedly to get a byte array from a string, but the only way I was successful was to use $encoding.getBytes(encodedString), not $somevariable.getBytes(regularString)The Java MessageDigest class also hashes a byte array and returns a byte array (that will match the .NET equivalent), so I'm not sure what you are getting at. Getting the ASCII/ UTF-8 value of a string by rakhesh is licensed under a Creative Commons Attribution 4.0 International License. By clicking “Post Your Answer”, you agree to our To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Comments are disabled for this blog but please email me with any comments, feedback, corrections, etc. site design / logo © 2020 Stack Exchange Inc; user contributions licensed under The objects converted from CSV are string values of the original objects that contain property values and no methods. Listing the cmdlet Set-Content's Supported EncodingsAdditional Information and Avoiding a Temporary FileListing the cmdlet Set-Content's Supported EncodingsAdditional Information and Avoiding a Temporary File Active 7 years, 9 months ago.

The problem occurred when I wanted to work on the CSV file using the PowerShell cmdlet Import-Csv, which, as far as I can tell, doesn't work correctly with latin1-encoded files exported from Excel or ANSI files created with notepad - if they contain non-US characters.

@James, it doesn't matter. What I meant by "api" is just the .Net Framework library. after being processed by Import-Csv.

I broke things down into discrete steps. If your Java code is hashing an already Base64 encoded string, then you can certainly do that in PowerShell too (but it would be unusual). Type "Get-Help Set-Content -Full" at a PowerShell prompt to read the help text, and see the example below. You have to pick a character encoding to convert between a string and a byte array. However, I needed to do the encryption first, then the encoding, but I did it the other way around.So, when I went to do the hashing I realized I had to have a byte[] from the string and I'm not sure how to do that. What I'm trying to do is use SHA1 UTF-8 encryption and then base64 encoding and on a password string value. Featured on Meta Without code or sample output I'm not sure we can help.Understood, I'll add the java code in now. Either way you have to map character data<=>byte data (streams are byte data). To simulate the situation, I open notepad and manually enter some data causing issues. What's the easiest way to convert XML from UTF16 to a UTF8 encoded file? ASCII, UTF-16, etc.

Then I when the encoding in java I get this: Encrypting a string directly is not supported. 5. W6ph5Mm5Pz8GgiULbPgzG37mj9g=but when I run it in PowerShell I get this because it's encoded first for UTF8:91 170 97 228 201 185 63 63 6 130 37 11 108 248 51 27 126 230 143 216Then when I run this line of code to convert it I get an error:However, if I run the new line of code to make it hex from below I get:Again, this may not even be possible to do, but I'm trying to find a work-around to see.You most likely just need to convert your hash to base64 after the last line.It looks like you're on the right track. Viewed 20k times 18. Maybe you could give us the output that the Java program produces...The .Net Framework library. It's implemented directly using the .NET System.String type, which is a reference type (read more about that in my A string can be arbitrarily long (computer memory and physics as we currently understand it allowing) and it is immutable, meaning it can't be changed without creating an entirely new altered version/"copy" of the string. Free 30 Day Trial You have an ANSI-encoded file, or a file encoded using some other (supported) encoding, and want to convert it to UTF-8 (or another supported encoding). Not sure if that was clear in earlier comments.I'm new to the .Net Framework, so while not directly supported, do you have a solution with code that could work? Here you see the Norwegian vowels are incorrectly displayed as question marks ("?") You have to pick a character encoding to convert between a string and a byte array.

Note: This answer applies to Windows PowerShell; by contrast, in the cross-platform PowerShell Core edition (v6+), UTF-8 without BOM is the default encoding, across all cmdlets. xml powershell utf-8 utf-16.

Converting xml from UTF-16 to UTF-8 using PowerShell. Correct or am I missing something here?When I run the java code with the password string of "password" I get[91, -86, 97, -28, -55, -71, 63, 63, 6, -126, 37, 11, 108, -8, 51, 27, 126, -26, -113, -40] Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Like using a Stream instead of a byte array? Also see the part about using Get-Content file.csv | ConvertFrom-Csv. The data contains the "extra" Norwegian vowels "æ", "ø" and "å", and their position in the Norwegian alphabet in a manually crafted CSV file. The java code does the encryption first with a message digest, then it does the UTF-8 encoding. – Gaara Dec 28 '12 at 16:06. A hack to list the supported encodings is to use one that doesn't exist: