==================================================================== */\r
package org.apache.poi.poifs.crypt;\r
\r
-import java.nio.charset.Charset;\r
+import java.io.UnsupportedEncodingException;\r
import java.security.DigestException;\r
import java.security.GeneralSecurityException;\r
import java.security.MessageDigest;\r
}\r
\r
public static byte[] getUtf16LeString(String str) {\r
- Charset cs = Charset.forName("UTF-16LE");\r
- return str.getBytes(cs);\r
+ try {\r
+ return str.getBytes("UTF-16LE");\r
+ } catch (UnsupportedEncodingException e) {\r
+ throw new EncryptedDocumentException(e);\r
+ }\r
}\r
\r
public static MessageDigest getMessageDigest(HashAlgorithm hashAlgorithm) {\r
package org.apache.poi.poifs.crypt;\r
\r
import java.io.IOException;\r
-import java.nio.charset.Charset;\r
+import java.io.UnsupportedEncodingException;\r
\r
import org.apache.poi.EncryptedDocumentException;\r
import org.apache.poi.poifs.crypt.standard.EncryptionRecord;\r
}\r
\r
public static String readUnicodeLPP4(LittleEndianInput is) {\r
- Charset cs = Charset.forName("UTF-16LE");\r
int length = is.readInt();\r
byte data[] = new byte[length];\r
is.readFully(data);\r
// 2 bytes long, and each byte MUST be 0x00. \r
is.readShort();\r
}\r
- return new String(data, 0, data.length, cs);\r
+ try {\r
+ return new String(data, 0, data.length, "UTF-16LE");\r
+ } catch (UnsupportedEncodingException e) {\r
+ throw new EncryptedDocumentException(e);\r
+ }\r
}\r
\r
public static void writeUnicodeLPP4(LittleEndianOutput os, String str) {\r
- Charset cs = Charset.forName("UTF-16LE");\r
- byte buf[] = str.getBytes(cs);\r
- os.writeInt(buf.length);\r
- os.write(buf);\r
- if (buf.length%4==2) {\r
- os.writeShort(0);\r
+ try {\r
+ byte buf[] = str.getBytes("UTF-16LE");\r
+ os.writeInt(buf.length);\r
+ os.write(buf);\r
+ if (buf.length%4==2) {\r
+ os.writeShort(0);\r
+ }\r
+ } catch (UnsupportedEncodingException e) {\r
+ throw new EncryptedDocumentException(e);\r
}\r
}\r
\r
is.readByte();\r
}\r
}\r
- Charset cs = Charset.forName("UTF-8");\r
- return new String(data, 0, data.length, cs);\r
+ try {\r
+ return new String(data, 0, data.length, "UTF-8");\r
+ } catch (UnsupportedEncodingException e) {\r
+ throw new EncryptedDocumentException(e);\r
+ }\r
}\r
\r
public static void writeUtf8LPP4(LittleEndianOutput os, String str) {\r
os.writeInt(str == null ? 0 : 4);\r
os.writeInt(0);\r
} else {\r
- Charset cs = Charset.forName("UTF-8");\r
- byte buf[] = str.getBytes(cs);\r
- os.writeInt(buf.length);\r
- os.write(buf);\r
- int scratchBytes = buf.length%4;\r
- if (scratchBytes > 0) {\r
- for (int i=0; i<(4-scratchBytes); i++) {\r
- os.writeByte(0);\r
+ try {\r
+ byte buf[] = str.getBytes("UTF-8");\r
+ os.writeInt(buf.length);\r
+ os.write(buf);\r
+ int scratchBytes = buf.length%4;\r
+ if (scratchBytes > 0) {\r
+ for (int i=0; i<(4-scratchBytes); i++) {\r
+ os.writeByte(0);\r
+ }\r
}\r
+ } catch (UnsupportedEncodingException e) {\r
+ throw new EncryptedDocumentException(e);\r
}\r
} \r
}\r
EncryptionInfoBuilder eib;
try {
eib = getBuilder(encryptionMode);
- } catch (ReflectiveOperationException e) {
+ } catch (Exception e) {
throw new IOException(e);
}
EncryptionInfoBuilder eib;
try {
eib = getBuilder(encryptionMode);
- } catch (ReflectiveOperationException e) {
+ } catch (Exception e) {
throw new EncryptedDocumentException(e);
}
}
protected static EncryptionInfoBuilder getBuilder(EncryptionMode encryptionMode)
- throws ReflectiveOperationException {
+ throws ClassNotFoundException, IllegalAccessException, InstantiationException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
EncryptionInfoBuilder eib;
eib = (EncryptionInfoBuilder)cl.loadClass(encryptionMode.builder).newInstance();