md5 ( "MD5", -1, "MD5", 16, "HmacMD5", false),\r
// although sunjc2 supports md2, hmac-md2 is only supported by bouncycastle\r
md2 ( "MD2", -1, "MD2", 16, "Hmac-MD2", true),\r
+ md4 ( "MD4", -1, "MD4", 16, "Hmac-MD4", true),\r
ripemd128("RipeMD128", -1, "RIPEMD-128", 16, "HMac-RipeMD128", true),\r
ripemd160("RipeMD160", -1, "RIPEMD-160", 20, "HMac-RipeMD160", true),\r
whirlpool("Whirlpool", -1, "WHIRLPOOL", 64, "HMac-Whirlpool", true),\r
import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.crypto.Cipher;
byte encryptedVerifier[] = ver.getEncryptedVerifier();
byte verifier[] = cipher.doFinal(encryptedVerifier);
setVerifier(verifier);
- MessageDigest sha1 = MessageDigest.getInstance(ver.getHashAlgorithm().jceId);
+ MessageDigest sha1 = CryptoFunctions.getMessageDigest(ver.getHashAlgorithm());
byte[] calcVerifierHash = sha1.digest(verifier);
byte encryptedVerifierHash[] = ver.getEncryptedVerifierHash();
byte decryptedVerifierHash[] = cipher.doFinal(encryptedVerifierHash);
buff[i] = (byte) (buff[i] ^ hash[i]);
}
- try {
- MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
- return sha1.digest(buff);
- } catch (NoSuchAlgorithmException e) {
- throw new EncryptedDocumentException("hash algo not supported", e);
- }
+ MessageDigest sha1 = CryptoFunctions.getMessageDigest(HashAlgorithm.sha1);
+ return sha1.digest(buff);
}
/**
\r
try {\r
byte encryptedVerifier[] = cipher.doFinal(verifier); \r
- MessageDigest hashAlgo = MessageDigest.getInstance(ver.getHashAlgorithm().jceId);\r
+ MessageDigest hashAlgo = CryptoFunctions.getMessageDigest(ver.getHashAlgorithm());\r
byte calcVerifierHash[] = hashAlgo.digest(verifier);\r
\r
// 2.3.3 EncryptionVerifier ...\r
providerType = STCryptProv.RSA_FULL;
sid = 1;
break;
- // md4 is not supported by JCE
+ case md4:
+ providerType = STCryptProv.RSA_FULL;
+ sid = 2;
+ break;
case md5:
providerType = STCryptProv.RSA_FULL;
sid = 3;
HashAlgorithm hashAlgo;
switch (sid.intValue()) {
case 1: hashAlgo = HashAlgorithm.md2; break;
+ case 2: hashAlgo = HashAlgorithm.md4; break;
case 3: hashAlgo = HashAlgorithm.md5; break;
case 4: hashAlgo = HashAlgorithm.sha1; break;
case 12: hashAlgo = HashAlgorithm.sha256; break;
==================================================================== */\r
package org.apache.poi.poifs.crypt;\r
\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
import java.io.ByteArrayInputStream;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.util.zip.ZipEntry;\r
import java.util.zip.ZipInputStream;\r
\r
-import junit.framework.TestCase;\r
-\r
import org.apache.poi.POIDataSamples;\r
import org.apache.poi.poifs.filesystem.POIFSFileSystem;\r
+import org.junit.Test;\r
\r
/**\r
* @author Maxim Valyanskiy\r
* @author Gary King\r
*/\r
-public class TestDecryptor extends TestCase {\r
- public void testPasswordVerification() throws IOException, GeneralSecurityException {\r
+public class TestDecryptor {\r
+ @Test\r
+ public void passwordVerification() throws IOException, GeneralSecurityException {\r
POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));\r
\r
EncryptionInfo info = new EncryptionInfo(fs);\r
assertTrue(d.verifyPassword(Decryptor.DEFAULT_PASSWORD));\r
}\r
\r
- public void testDecrypt() throws IOException, GeneralSecurityException {\r
+ @Test\r
+ public void decrypt() throws IOException, GeneralSecurityException {\r
POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));\r
\r
EncryptionInfo info = new EncryptionInfo(fs);\r
zipOk(fs, d);\r
}\r
\r
- public void testAgile() throws IOException, GeneralSecurityException {\r
+ @Test\r
+ public void agile() throws IOException, GeneralSecurityException {\r
POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protected_agile.docx"));\r
\r
EncryptionInfo info = new EncryptionInfo(fs);\r
}\r
}\r
}\r
- public void testDataLength() throws Exception {\r
+\r
+ @Test\r
+ public void dataLength() throws Exception {\r
POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protected_agile.docx"));\r
\r
EncryptionInfo info = new EncryptionInfo(fs);\r