summaryrefslogtreecommitdiffstats
path: root/comphelper
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-02-24 11:45:34 +0100
committerEike Rathke <erack@redhat.com>2018-02-24 11:47:09 +0100
commit89182507aaf336d16ba1e89305bc2ea3b1e6949f (patch)
treecb3a96d942e0c2260d78372a889562817b9f08bf /comphelper
parentHold ScOoxPasswordHash at ScTableProtectionImpl, tdf#104250 prep (diff)
downloadcore-89182507aaf336d16ba1e89305bc2ea3b1e6949f.tar.gz
core-89182507aaf336d16ba1e89305bc2ea3b1e6949f.zip
Hash Base64, Sequence and cleansing, tdf#104250 prep
Change-Id: I58d48b8caa780138b8431bec9db20c9d0e9abce7
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/qa/unit/test_hash.cxx4
-rw-r--r--comphelper/source/misc/hash.cxx33
2 files changed, 25 insertions, 12 deletions
diff --git a/comphelper/qa/unit/test_hash.cxx b/comphelper/qa/unit/test_hash.cxx
index beec2c537cf4..e15b906c190f 100644
--- a/comphelper/qa/unit/test_hash.cxx
+++ b/comphelper/qa/unit/test_hash.cxx
@@ -111,8 +111,8 @@ void TestHash::testSHA512_saltspin()
const OUString aPass("pwd");
const OUString aAlgo("SHA-512");
const OUString aSalt("876MLoKTq42+/DLp415iZQ==");
- const OUString aHash = comphelper::Hash::calculateHash( aPass, aSalt, 100000, aAlgo);
- OUString aStr("5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g==");
+ const OUString aHash = comphelper::Hash::calculateHashBase64( aPass, aSalt, 100000, aAlgo);
+ const OUString aStr("5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g==");
CPPUNIT_ASSERT_EQUAL(aStr, aHash);
}
diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx
index 7a8c3fecd7e9..0a91536347b9 100644
--- a/comphelper/source/misc/hash.cxx
+++ b/comphelper/source/misc/hash.cxx
@@ -168,7 +168,6 @@ std::vector<unsigned char> Hash::calculateHash(
return calculateHash( pInput, nLength, eType);
Hash aHash(eType);
- std::vector<unsigned char> hash;
if (nSaltLen)
{
std::vector<unsigned char> initialData( nSaltLen + nLength);
@@ -181,7 +180,7 @@ std::vector<unsigned char> Hash::calculateHash(
{
aHash.update( pInput, nLength);
}
- hash = aHash.finalize();
+ std::vector<unsigned char> hash( aHash.finalize());
if (nSpinCount)
{
@@ -232,7 +231,7 @@ std::vector<unsigned char> Hash::calculateHash(
return calculateHash( pPassBytes, nPassBytesLen, rSaltValue.data(), rSaltValue.size(), nSpinCount, eType);
}
-OUString Hash::calculateHash(
+css::uno::Sequence<sal_Int8> Hash::calculateHashSequence(
const rtl::OUString& rPassword,
const rtl::OUString& rSaltValue,
sal_uInt32 nSpinCount,
@@ -248,17 +247,31 @@ OUString Hash::calculateHash(
else if (rAlgorithmName == "MD5")
eType = HashType::MD5;
else
- return OUString();
+ return css::uno::Sequence<sal_Int8>();
- css::uno::Sequence<sal_Int8> aSaltSeq;
- comphelper::Base64::decode( aSaltSeq, rSaltValue);
+ std::vector<unsigned char> aSaltVec;
+ if (!rSaltValue.isEmpty())
+ {
+ css::uno::Sequence<sal_Int8> aSaltSeq;
+ comphelper::Base64::decode( aSaltSeq, rSaltValue);
+ aSaltVec = comphelper::sequenceToContainer<std::vector<unsigned char>>( aSaltSeq);
+ }
+
+ std::vector<unsigned char> hash( calculateHash( rPassword, aSaltVec, nSpinCount, eType));
+
+ return comphelper::containerToSequence<sal_Int8>( hash);
+}
- std::vector<unsigned char> hash = calculateHash( rPassword,
- comphelper::sequenceToContainer<std::vector<unsigned char>>( aSaltSeq),
- nSpinCount, eType);
+OUString Hash::calculateHashBase64(
+ const rtl::OUString& rPassword,
+ const rtl::OUString& rSaltValue,
+ sal_uInt32 nSpinCount,
+ const rtl::OUString& rAlgorithmName)
+{
+ css::uno::Sequence<sal_Int8> aSeq( calculateHashSequence( rPassword, rSaltValue, nSpinCount, rAlgorithmName));
OUStringBuffer aBuf;
- comphelper::Base64::encode( aBuf, comphelper::containerToSequence<sal_Int8>( hash));
+ comphelper::Base64::encode( aBuf, aSeq);
return aBuf.makeStringAndClear();
}