有人可以告诉我更多有关EncryptionMode.agile的信息吗? 它使用什么样的算法? 我只有像这样的pw protectet xlsx文件
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
// EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile, CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null);
Encryptor enc = info.getEncryptor();
enc.confirmPassword(password);
System.out.println("Read in an existing OOXML file ...");
OPCPackage opc = OPCPackage.open(new File(filepathname), PackageAccess.READ_WRITE);
编辑: 我正在生成一个xlsx文件,将一些testdata放入其中并加密以获得pw保护
EDIT2: 这是在EncriptionInfo中。只是看看里面
...
/**
* Prepares for encryption, using the given Encryption Mode, and
* all other parameters as default.
* @see #EncryptionInfo(EncryptionMode, CipherAlgorithm, HashAlgorithm, int, int, ChainingMode)
*/
public EncryptionInfo(EncryptionMode encryptionMode) {
this(encryptionMode, null, null, -1, -1, null);
}
/**
* Constructs an EncryptionInfo from scratch
*
* @param encryptionMode see {@link EncryptionMode} for values, {@link EncryptionMode#cryptoAPI} is for
* internal use only, as it's record based
* @param cipherAlgorithm
* @param hashAlgorithm
* @param keyBits
* @param blockSize
* @param chainingMode
*
* @throws EncryptedDocumentException if the given parameters mismatch, e.g. only certain combinations
* of keyBits, blockSize are allowed for a given {@link CipherAlgorithm}
*/
public EncryptionInfo(
EncryptionMode encryptionMode
, CipherAlgorithm cipherAlgorithm
, HashAlgorithm hashAlgorithm
, int keyBits
, int blockSize
, ChainingMode chainingMode
) {
versionMajor = encryptionMode.versionMajor;
versionMinor = encryptionMode.versionMinor;
encryptionFlags = encryptionMode.encryptionFlags;
EncryptionInfoBuilder eib;
try {
eib = getBuilder(encryptionMode);
} catch (Exception e) {
throw new EncryptedDocumentException(e);
}
eib.initialize(this, cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode);
header = eib.getHeader();
verifier = eib.getVerifier();
decryptor = eib.getDecryptor();
encryptor = eib.getEncryptor();
}...
这是在AgileEncyptionInfoBuilder中 ...
@Override
public void initialize(EncryptionInfo ei, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) {
this.info = ei;
if (cipherAlgorithm == null) {
cipherAlgorithm = CipherAlgorithm.aes128;
}
if (cipherAlgorithm == CipherAlgorithm.rc4) {
throw new EncryptedDocumentException("RC4 must not be used with agile encryption.");
}
if (hashAlgorithm == null) {
hashAlgorithm = HashAlgorithm.sha1;
}
if (chainingMode == null) {
chainingMode = ChainingMode.cbc;
}...
可能你还需要在windows上安装JCE
这是一个很好的指南: http://suhothayan.blogspot.de/2012/05/how-to-install-java-cryptography.html (只需覆盖lib \ security中的.jar,所有。在jre和jdk位置上)
或使用Bouncy Castle 并且不要使用" VelvetSweatshop"作为.xlsx密码:D