Kaydet (Commit) 94fa259e authored tarafından Eike Rathke's avatar Eike Rathke

Introduce DocPasswordHelper::GetOoxHashAsVector() with salt value vector

In preparation to use this in AgileEngine.

Change-Id: I45fb6ba24b759a72af0c7afa22eae75f1ae728ce
üst 3c0189c7
......@@ -259,9 +259,9 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence(
}
css::uno::Sequence<sal_Int8> DocPasswordHelper::GetOoxHashAsSequence(
std::vector<unsigned char> DocPasswordHelper::GetOoxHashAsVector(
const rtl::OUString& rPassword,
const rtl::OUString& rSaltValue,
const std::vector<unsigned char>& rSaltValue,
sal_uInt32 nSpinCount,
comphelper::Hash::IterCount eIterCount,
const rtl::OUString& rAlgorithmName)
......@@ -276,8 +276,19 @@ css::uno::Sequence<sal_Int8> DocPasswordHelper::GetOoxHashAsSequence(
else if (rAlgorithmName == "MD5")
eType = comphelper::HashType::MD5;
else
return css::uno::Sequence<sal_Int8>();
return std::vector<unsigned char>();
return comphelper::Hash::calculateHash( rPassword, rSaltValue, nSpinCount, eIterCount, eType);
}
css::uno::Sequence<sal_Int8> DocPasswordHelper::GetOoxHashAsSequence(
const rtl::OUString& rPassword,
const rtl::OUString& rSaltValue,
sal_uInt32 nSpinCount,
comphelper::Hash::IterCount eIterCount,
const rtl::OUString& rAlgorithmName)
{
std::vector<unsigned char> aSaltVec;
if (!rSaltValue.isEmpty())
{
......@@ -286,8 +297,7 @@ css::uno::Sequence<sal_Int8> DocPasswordHelper::GetOoxHashAsSequence(
aSaltVec = comphelper::sequenceToContainer<std::vector<unsigned char>>( aSaltSeq);
}
std::vector<unsigned char> hash( comphelper::Hash::calculateHash( rPassword, aSaltVec, nSpinCount,
eIterCount, eType));
std::vector<unsigned char> hash( GetOoxHashAsVector( rPassword, aSaltVec, nSpinCount, eIterCount, rAlgorithmName));
return comphelper::containerToSequence<sal_Int8>( hash);
}
......
......@@ -183,7 +183,10 @@ public:
/** Convenience function to calculate a salted hash with iterations as
specified in https://msdn.microsoft.com/en-us/library/dd920692 for the
OOXML sheetProtection and fileSharing elements.
OOXML sheetProtection and fileSharing elements, or
https://msdn.microsoft.com/en-us/library/dd924776 and
https://msdn.microsoft.com/en-us/library/dd925430 for Standard and
Agile Encryption.
@param rPassword
UTF-16 encoded string without leading BOM character
......@@ -225,7 +228,10 @@ public:
/** Convenience function to calculate a salted hash with iterations as
specified in https://msdn.microsoft.com/en-us/library/dd920692 for the
OOXML sheetProtection and fileSharing elements.
OOXML sheetProtection and fileSharing elements, or
https://msdn.microsoft.com/en-us/library/dd924776 and
https://msdn.microsoft.com/en-us/library/dd925430 for Standard and
Agile Encryption.
@param rPassword
UTF-16 encoded string without leading BOM character
......@@ -266,6 +272,50 @@ public:
const rtl::OUString& rAlgorithmName);
/** Convenience function to calculate a salted hash with iterations as
specified in https://msdn.microsoft.com/en-us/library/dd920692 for the
OOXML sheetProtection and fileSharing elements, or
https://msdn.microsoft.com/en-us/library/dd924776 and
https://msdn.microsoft.com/en-us/library/dd925430 for Standard and
Agile Encryption.
@param rPassword
UTF-16 encoded string without leading BOM character
@param rSaltValue
A raw salt that will be prepended to password data.
@param nSpinCount
If >0 the number of repeated iterations.
@param eIterCount
If Hash::IterCount::APPEND, append iteration count as per
https://msdn.microsoft.com/en-us/library/dd920692
If Hash::IterCount::PREPEND, prepend iteration count as per
https://msdn.microsoft.com/en-us/library/dd924776 and
https://msdn.microsoft.com/en-us/library/dd925430
If Hash::IterCount::NONE, do not add the iteration count to hash
iterations.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed for AlgorithmName in
https://msdn.microsoft.com/en-us/library/dd920692
or "SHA512", "SHA256", ... as listed for HashAlgorithm in
https://msdn.microsoft.com/en-us/library/dd925810
that have a valid match in comphelper::HashType. If not, an
empty sequence is returned. Not all algorithm names are
supported.
@return the raw the hash value.
*/
static std::vector<unsigned char> GetOoxHashAsVector(
const rtl::OUString& rPassword,
const std::vector<unsigned char>& rSaltValue,
sal_uInt32 nSpinCount,
comphelper::Hash::IterCount eIterCount,
const rtl::OUString& rAlgorithmName);
/** This helper function generates a random sequence of bytes of
requested length.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment