is = new ByteArrayInputStream(descriptor.getBytes());
keyData = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(is)
.getElementsByTagName("keyData").item(0).getAttributes();
} catch (Exception e) {
throw new EncryptedDocumentException("Unable to parse keyData");
}
keySize = Integer.parseInt(keyData.getNamedItem("keyBits")
.getNodeValue());
flags = 0;
sizeExtra = 0;
cspName = null;
int blockSize = Integer.parseInt(keyData.getNamedItem("blockSize").
getNodeValue());
String cipher = keyData.getNamedItem("cipherAlgorithm").getNodeValue();
if ("AES".equals(cipher)) {
providerType = PROVIDER_AES;
if (blockSize == 16)
algorithm = ALGORITHM_AES_128;
else if (blockSize == 24)
algorithm = ALGORITHM_AES_192;
else if (blockSize == 32)
algorithm = ALGORITHM_AES_256;
else
throw new EncryptedDocumentException("Unsupported key length");
} else {
throw new EncryptedDocumentException("Unsupported cipher");
}
String chaining = keyData.getNamedItem("cipherChaining").getNodeValue();
if ("ChainingModeCBC".equals(chaining))
cipherMode = MODE_CBC;
else if ("ChainingModeCFB".equals(chaining))
cipherMode = MODE_CFB;
else
throw new EncryptedDocumentException("Unsupported chaining mode");
String hashAlg = keyData.getNamedItem("hashAlgorithm").getNodeValue();
int hashSize = Integer.parseInt(keyData.getNamedItem("hashSize")
.getNodeValue());
if ("SHA1".equals(hashAlg) && hashSize == 20)
hashAlgorithm = HASH_SHA1;
else
throw new EncryptedDocumentException("Unsupported hash algorithm");
String salt = keyData.getNamedItem("saltValue").getNodeValue();
int saltLength = Integer.parseInt(keyData.getNamedItem("saltSize")
.getNodeValue());
keySalt = Base64.decodeBase64(salt.getBytes());
if (keySalt.length != saltLength)
throw new EncryptedDocumentException("Invalid salt length");
}