Skip to content

Commit 49923a6

Browse files
fix encoding for base64 to StandardCharsets.US_ASCII
1 parent 28a3002 commit 49923a6

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.File;
2727
import java.io.IOException;
28+
import java.nio.charset.StandardCharsets;
2829
import java.nio.file.Files;
2930
import java.nio.file.Path;
3031
import java.nio.file.Paths;
@@ -63,20 +64,20 @@ static void writeFile(File folder, String file, String content) {
6364

6465
/**
6566
* Read the content of a {@link File} and convert it to a String in base 64.
66-
* We expect the content of the file to be encoded using {@link com.cloud.utils.StringUtils#getPreferredCharset()}
67+
* We expect the content of the file to be encoded using {@link StandardCharsets#US_ASC}
6768
*/
6869
public static String fileToBase64String(File isoFile) throws IOException {
6970
byte[] encoded = Base64.encodeBase64(FileUtils.readFileToByteArray(isoFile));
70-
return new String(encoded, com.cloud.utils.StringUtils.getPreferredCharset());
71+
return new String(encoded, StandardCharsets.US_ASCII);
7172
}
7273

7374
/**
7475
* Writes a String encoded in base 64 to a file in the given folder.
7576
* The content will be decoded and then written to the file. Be aware that we will overwrite the content of the file if it already exists.
76-
* Moreover, the content will must be encoded in {@link com.cloud.utils.StringUtils#getPreferredCharset()} before it is encoded in base 64.
77+
* Moreover, the content will must be encoded in {@link StandardCharsets#US_ASCII} before it is encoded in base 64.
7778
*/
7879
public static File base64StringToFile(String encodedIsoData, String folder, String fileName) throws IOException {
79-
byte[] decoded = Base64.decodeBase64(encodedIsoData.getBytes(com.cloud.utils.StringUtils.getPreferredCharset()));
80+
byte[] decoded = Base64.decodeBase64(encodedIsoData.getBytes(StandardCharsets.US_ASCII));
8081
Path destPath = Paths.get(folder, fileName);
8182
return Files.write(destPath, decoded).toFile();
8283
}

0 commit comments

Comments
 (0)