This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch odf-devel
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit a307e3aa559c62ea234827d7c4f1ee44708bf25d
Author: Jim Jagielski <[email protected]>
AuthorDate: Thu Oct 29 14:05:54 2026 -0400

    svl, sc, sw, xmloff: write protection keys as SHA-256 of the UTF-8 password 
with the digest algorithm attribute (ODF 1.2)
    
    Older AOO releases cannot unprotect a sheet saved this way. The reader 
accepts SHA-1 over UTF-16LE, UTF-16BE or UTF-8 and SHA-256 over UTF-8, chosen 
by key length.
---
 main/sc/inc/tabprotection.hxx                |   5 +-
 main/sc/source/core/data/tabprotection.cxx   |  13 +++
 main/sc/source/filter/xml/xmlexprt.cxx       |  31 +++++++-
 main/svl/inc/svl/PasswordHelper.hxx          |   7 ++
 main/svl/source/misc/PasswordHelper.cxx      | 113 ++++++++++++++++++++++++---
 main/sw/source/ui/dialog/uiregionsw.cxx      |   6 +-
 main/xmloff/inc/xmloff/xmltoken.hxx          |   1 +
 main/xmloff/source/core/xmltoken.cxx         |   1 +
 main/xmloff/source/text/XMLSectionExport.cxx |  10 +++
 9 files changed, 170 insertions(+), 17 deletions(-)

diff --git a/main/sc/inc/tabprotection.hxx b/main/sc/inc/tabprotection.hxx
index f527e74695..fbab063494 100644
--- a/main/sc/inc/tabprotection.hxx
+++ b/main/sc/inc/tabprotection.hxx
@@ -38,8 +38,9 @@ class ScTableProtectionImpl;
 
 enum ScPasswordHash
 {
-    PASSHASH_OOO = 0,
-    PASSHASH_XL
+    PASSHASH_OOO = 0,   // ODF hash: SHA-1 (20 bytes) or SHA-256 of the UTF-8 
password (32 bytes)
+    PASSHASH_XL,
+    PASSHASH_SHA256     // only requested from getPasswordHash(); never stored 
as the tag
 };
 
 class ScPassHashHelper
diff --git a/main/sc/source/core/data/tabprotection.cxx 
b/main/sc/source/core/data/tabprotection.cxx
index ee806eb045..3e0a18040e 100644
--- a/main/sc/source/core/data/tabprotection.cxx
+++ b/main/sc/source/core/data/tabprotection.cxx
@@ -111,6 +111,9 @@ Sequence<sal_Int8> 
ScTableProtectionImpl::hashPassword(const String& aPassText,
         case PASSHASH_XL:
             aHash = ::comphelper::DocPasswordHelper::GetXLHashAsSequence( 
aPassText, RTL_TEXTENCODING_UTF8 );
         break;
+        case PASSHASH_SHA256:
+            SvPasswordHelper::GetHashPasswordSHA256(aHash, aPassText);
+        break;
         case PASSHASH_OOO:
         default:
             SvPasswordHelper::GetHashPassword(aHash, aPassText);
@@ -188,6 +191,9 @@ bool ScTableProtectionImpl::hasPasswordHash(ScPasswordHash 
eHash) const
     if (meHash == eHash)
         return true;
 
+    if (eHash == PASSHASH_SHA256 && meHash == PASSHASH_OOO && 
maPassHash.getLength() == 32)
+        return true;
+
     return false;
 }
 
@@ -205,6 +211,9 @@ Sequence<sal_Int8> 
ScTableProtectionImpl::getPasswordHash(ScPasswordHash eHash)
         // Stored hash exists.
         return maPassHash;
 
+    if (eHash == PASSHASH_SHA256 && meHash == PASSHASH_OOO && 
maPassHash.getLength() == 32)
+        return maPassHash;
+
     // Failed to find a matching hash.
     return Sequence<sal_Int8>();
 }
@@ -237,6 +246,10 @@ bool ScTableProtectionImpl::verifyPassword(const String& 
aPassText) const
         // Clear text password exists, and this one takes precedence.
         return aPassText.Equals(maPassText);
 
+    if (meHash == PASSHASH_OOO)
+        // the ODF key may be SHA-1 over UTF-16LE/BE/UTF-8 or SHA-256 over 
UTF-8
+        return SvPasswordHelper::CompareHashPassword(maPassHash, aPassText);
+
     Sequence<sal_Int8> aHash = hashPassword(aPassText, meHash);
 
 #if DEBUG_TAB_PROTECTION
diff --git a/main/sc/source/filter/xml/xmlexprt.cxx 
b/main/sc/source/filter/xml/xmlexprt.cxx
index 3519ceb62c..6945afc7ce 100644
--- a/main/sc/source/filter/xml/xmlexprt.cxx
+++ b/main/sc/source/filter/xml/xmlexprt.cxx
@@ -65,6 +65,7 @@
 #include "externalrefmgr.hxx"
 #include "editutil.hxx"
 #include "tabprotection.hxx"
+#include <svl/PasswordHelper.hxx>
 
 #include <xmloff/xmltoken.hxx>
 #include <xmloff/xmlnmspe.hxx>
@@ -1509,6 +1510,22 @@ void ScXMLExport::FillColumnRowGroups()
        }
 }
 
+// ODF 1.2 19.698: SHA-256 of the UTF-8 password; a stored SHA-1 key and ODF 
1.0/1.1 keep what the model has
+static uno::Sequence<sal_Int8> lcl_GetProtectionKey( const 
ScPassHashProtectable& rProtect,
+        bool bODF12, rtl::OUString& rDigest )
+{
+    if (bODF12 && rProtect.hasPasswordHash(PASSHASH_SHA256))
+    {
+        uno::Sequence<sal_Int8> aKey = 
rProtect.getPasswordHash(PASSHASH_SHA256);
+        if (aKey.getLength())
+        {
+            rDigest = SvPasswordHelper::GetDigestAlgorithmIRI(aKey);
+            return aKey;
+        }
+    }
+    return rProtect.getPasswordHash(PASSHASH_OOO);
+}
+
 void ScXMLExport::SetBodyAttributes()
 {
        if (pDoc && pDoc->IsDocProtected())
@@ -1516,12 +1533,17 @@ void ScXMLExport::SetBodyAttributes()
                AddAttribute(XML_NAMESPACE_TABLE, XML_STRUCTURE_PROTECTED, 
XML_TRUE);
                rtl::OUStringBuffer aBuffer;
         uno::Sequence<sal_Int8> aPassHash;
+        rtl::OUString aDigest;
         const ScDocProtection* p = pDoc->GetDocProtection();
         if (p)
-            aPassHash = p->getPasswordHash(PASSHASH_OOO);
+            aPassHash = lcl_GetProtectionKey(*p, getDefaultVersion() >= 
SvtSaveOptions::ODFVER_012, aDigest);
                SvXMLUnitConverter::encodeBase64(aBuffer, aPassHash);
                if (aBuffer.getLength())
+               {
                        AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, 
aBuffer.makeStringAndClear());
+                       if (aDigest.getLength())
+                               AddAttribute(XML_NAMESPACE_TABLE, 
XML_PROTECTION_KEY_DIGEST_ALGORITHM, aDigest);
+               }
        }
 }
 
@@ -1725,14 +1747,19 @@ void ScXMLExport::_ExportContent()
                         {
                             AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, 
XML_TRUE);
                             rtl::OUStringBuffer aBuffer;
+                            rtl::OUString aDigest;
                             if (pDoc)
                             {
                                 ScTableProtection* pProtect = 
pDoc->GetTabProtection(static_cast<SCTAB>(nTable));
                                 if (pProtect)
-                                    SvXMLUnitConverter::encodeBase64(aBuffer, 
pProtect->getPasswordHash(PASSHASH_OOO));
+                                    SvXMLUnitConverter::encodeBase64(aBuffer, 
lcl_GetProtectionKey(*pProtect, getDefaultVersion() >= 
SvtSaveOptions::ODFVER_012, aDigest));
                             }
                             if (aBuffer.getLength())
+                            {
                                 AddAttribute(XML_NAMESPACE_TABLE, 
XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
+                                if (aDigest.getLength())
+                                    AddAttribute(XML_NAMESPACE_TABLE, 
XML_PROTECTION_KEY_DIGEST_ALGORITHM, aDigest);
+                            }
                         }
                         rtl::OUString sPrintRanges;
                         table::CellRangeAddress aColumnHeaderRange;
diff --git a/main/svl/inc/svl/PasswordHelper.hxx 
b/main/svl/inc/svl/PasswordHelper.hxx
index 5ca5cd287e..275167538b 100644
--- a/main/svl/inc/svl/PasswordHelper.hxx
+++ b/main/svl/inc/svl/PasswordHelper.hxx
@@ -27,6 +27,7 @@
 #include "svl/svldllapi.h"
 #include "sal/types.h"
 #include "com/sun/star/uno/Sequence.hxx"
+#include "rtl/ustring.hxx"
 
 class String;
 
@@ -35,13 +36,19 @@ class SvPasswordHelper
        static void             GetHashPassword(com::sun::star::uno::Sequence 
<sal_Int8>& rPassHash, const sal_Char* pPass, sal_uInt32 nLen);
     static void     
GetHashPasswordLittleEndian(com::sun::star::uno::Sequence<sal_Int8>& rPassHash, 
const String& sPass);
     static void     
GetHashPasswordBigEndian(com::sun::star::uno::Sequence<sal_Int8>& rPassHash, 
const String& sPass);
+    static void     
GetHashPasswordUTF8(com::sun::star::uno::Sequence<sal_Int8>& rPassHash, const 
String& sPass);
 
 public:
     SVL_DLLPUBLIC static void     
GetHashPassword(com::sun::star::uno::Sequence<sal_Int8>& rPassHash, const 
String& sPass);
+    /** SHA-256 of the UTF-8 password, the form ODF 1.2 (19.698, 19.851) asks 
producers to use */
+    SVL_DLLPUBLIC static void     
GetHashPasswordSHA256(com::sun::star::uno::Sequence<sal_Int8>& rPassHash, const 
String& sPass);
+    /** the ODF 1.2 digest algorithm IRI for a hash made by 
GetHashPasswordSHA256, empty for any other hash */
+    SVL_DLLPUBLIC static ::rtl::OUString GetDigestAlgorithmIRI(const 
com::sun::star::uno::Sequence<sal_Int8>& rPassHash);
     /**
     Use this method to compare a given string with another given Hash value.
     This is necessary, because in older versions exists different hashs of the 
same string. They were endian dependent.
     We need this to handle old files. This method will compare against big and 
little endian. See #101326#
+    A 20 byte hash is SHA-1 of the password as UTF-16LE, UTF-16BE or UTF-8; a 
32 byte hash is SHA-256 of the UTF-8 password.
     */
     SVL_DLLPUBLIC static bool     CompareHashPassword(const 
com::sun::star::uno::Sequence<sal_Int8>& rOldPassHash, const String& sNewPass);
 };
diff --git a/main/svl/source/misc/PasswordHelper.cxx 
b/main/svl/source/misc/PasswordHelper.cxx
index 278bbd5ad9..f3f5029c1f 100644
--- a/main/svl/source/misc/PasswordHelper.cxx
+++ b/main/svl/source/misc/PasswordHelper.cxx
@@ -30,6 +30,74 @@
 
 using namespace com::sun::star;
 
+namespace
+{
+const sal_uInt32 SHA256_K[64] = {
+    0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 
0x923f82a4, 0xab1c5ed5,
+    0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 
0x9bdc06a7, 0xc19bf174,
+    0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 
0x5cb0a9dc, 0x76f988da,
+    0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 
0x06ca6351, 0x14292967,
+    0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 
0x81c2c92e, 0x92722c85,
+    0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 
0xf40e3585, 0x106aa070,
+    0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 
0x5b9cca4f, 0x682e6ff3,
+    0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 
0xbef9a3f7, 0xc67178f2
+};
+
+inline sal_uInt32 lcl_Rotr( sal_uInt32 n, int b ) { return ( n >> b ) | ( n << 
( 32 - b ) ); }
+
+void lcl_Sha256Block( sal_uInt32* pState, const sal_uInt8* pBlock )
+{
+    sal_uInt32 w[64];
+    for( int i = 0; i < 16; ++i )
+        w[i] = ( sal_uInt32( pBlock[4*i] ) << 24 ) | ( sal_uInt32( 
pBlock[4*i+1] ) << 16 ) |
+               ( sal_uInt32( pBlock[4*i+2] ) << 8 ) | sal_uInt32( 
pBlock[4*i+3] );
+    for( int i = 16; i < 64; ++i )
+    {
+        const sal_uInt32 s0 = lcl_Rotr( w[i-15], 7 ) ^ lcl_Rotr( w[i-15], 18 ) 
^ ( w[i-15] >> 3 );
+        const sal_uInt32 s1 = lcl_Rotr( w[i-2], 17 ) ^ lcl_Rotr( w[i-2], 19 ) 
^ ( w[i-2] >> 10 );
+        w[i] = w[i-16] + s0 + w[i-7] + s1;
+    }
+    sal_uInt32 a = pState[0], b = pState[1], c = pState[2], d = pState[3];
+    sal_uInt32 e = pState[4], f = pState[5], g = pState[6], h = pState[7];
+    for( int i = 0; i < 64; ++i )
+    {
+        const sal_uInt32 t1 = h + ( lcl_Rotr( e, 6 ) ^ lcl_Rotr( e, 11 ) ^ 
lcl_Rotr( e, 25 ) ) +
+                              ( ( e & f ) ^ ( ~e & g ) ) + SHA256_K[i] + w[i];
+        const sal_uInt32 t2 = ( lcl_Rotr( a, 2 ) ^ lcl_Rotr( a, 13 ) ^ 
lcl_Rotr( a, 22 ) ) +
+                              ( ( a & b ) ^ ( a & c ) ^ ( b & c ) );
+        h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2;
+    }
+    pState[0] += a; pState[1] += b; pState[2] += c; pState[3] += d;
+    pState[4] += e; pState[5] += f; pState[6] += g; pState[7] += h;
+}
+
+// sal has no SHA-256; FIPS 180-4
+void lcl_Sha256( const sal_uInt8* pData, sal_uInt32 nLen, sal_uInt8* pOut )
+{
+    sal_uInt32 aState[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
+                             0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
+    sal_uInt32 nDone = 0;
+    for( ; nLen - nDone >= 64; nDone += 64 )
+        lcl_Sha256Block( aState, pData + nDone );
+
+    sal_uInt8 aTail[128] = { 0 };
+    const sal_uInt32 nRest = nLen - nDone;
+    for( sal_uInt32 i = 0; i < nRest; ++i )
+        aTail[i] = pData[nDone + i];
+    aTail[nRest] = 0x80;
+    const sal_uInt32 nTailLen = nRest < 56 ? 64 : 128;
+    const sal_uInt64 nBits = sal_uInt64( nLen ) * 8;
+    for( int i = 0; i < 8; ++i )
+        aTail[nTailLen - 1 - i] = sal_uInt8( nBits >> ( 8 * i ) );
+    for( sal_uInt32 i = 0; i < nTailLen; i += 64 )
+        lcl_Sha256Block( aState, aTail + i );
+
+    for( int i = 0; i < 8; ++i )
+        for( int j = 0; j < 4; ++j )
+            pOut[4*i+j] = sal_uInt8( aState[i] >> ( 24 - 8 * j ) );
+}
+}
+
 void SvPasswordHelper::GetHashPassword(uno::Sequence<sal_Int8>& rPassHash, 
const sal_Char* pPass, sal_uInt32 nLen)
 {
     rPassHash.realloc(RTL_DIGEST_LENGTH_SHA1);
@@ -75,24 +143,49 @@ void 
SvPasswordHelper::GetHashPasswordBigEndian(uno::Sequence<sal_Int8>& rPassHa
     delete[] pCharBuffer;
 }
 
+void SvPasswordHelper::GetHashPasswordUTF8(uno::Sequence<sal_Int8>& rPassHash, 
const String& sPass)
+{
+    const ::rtl::OString aUtf8( ::rtl::OUStringToOString( ::rtl::OUString( 
sPass ), RTL_TEXTENCODING_UTF8 ) );
+    GetHashPassword(rPassHash, aUtf8.getStr(), aUtf8.getLength());
+}
+
 void SvPasswordHelper::GetHashPassword(uno::Sequence<sal_Int8>& rPassHash, 
const String& sPass)
 {
     GetHashPasswordLittleEndian(rPassHash, sPass);
 }
 
-bool SvPasswordHelper::CompareHashPassword(const uno::Sequence<sal_Int8>& 
rOldPassHash, const String& sNewPass)
+void SvPasswordHelper::GetHashPasswordSHA256(uno::Sequence<sal_Int8>& 
rPassHash, const String& sPass)
 {
-    bool bResult = false;
+    const ::rtl::OString aUtf8( ::rtl::OUStringToOString( ::rtl::OUString( 
sPass ), RTL_TEXTENCODING_UTF8 ) );
+    rPassHash.realloc(32);
+    lcl_Sha256( reinterpret_cast<const sal_uInt8*>(aUtf8.getStr()), 
aUtf8.getLength(),
+                reinterpret_cast<sal_uInt8*>(rPassHash.getArray()) );
+}
 
-    uno::Sequence<sal_Int8> aNewPass(RTL_DIGEST_LENGTH_SHA1);
-    GetHashPasswordLittleEndian(aNewPass, sNewPass);
-    if (aNewPass == rOldPassHash)
-        bResult = true;
-    else
+::rtl::OUString SvPasswordHelper::GetDigestAlgorithmIRI(const 
uno::Sequence<sal_Int8>& rPassHash)
+{
+    if (rPassHash.getLength() == 32)
+        return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"http://www.w3.org/2000/09/xmldsig#sha256"; ) );
+    return ::rtl::OUString();
+}
+
+bool SvPasswordHelper::CompareHashPassword(const uno::Sequence<sal_Int8>& 
rOldPassHash, const String& sNewPass)
+{
+    uno::Sequence<sal_Int8> aNewPass;
+    if (rOldPassHash.getLength() == 32)
     {
-        GetHashPasswordBigEndian(aNewPass, sNewPass);
-        bResult = (aNewPass == rOldPassHash);
+        GetHashPasswordSHA256(aNewPass, sNewPass);
+        return aNewPass == rOldPassHash;
     }
+    if (rOldPassHash.getLength() != RTL_DIGEST_LENGTH_SHA1)
+        return false;
 
-    return bResult;
+    GetHashPasswordLittleEndian(aNewPass, sNewPass);
+    if (aNewPass == rOldPassHash)
+        return true;
+    GetHashPasswordBigEndian(aNewPass, sNewPass);
+    if (aNewPass == rOldPassHash)
+        return true;
+    GetHashPasswordUTF8(aNewPass, sNewPass);
+    return aNewPass == rOldPassHash;
 }
diff --git a/main/sw/source/ui/dialog/uiregionsw.cxx 
b/main/sw/source/ui/dialog/uiregionsw.cxx
index 6c11bda72f..98eefe1e2e 100644
--- a/main/sw/source/ui/dialog/uiregionsw.cxx
+++ b/main/sw/source/ui/dialog/uiregionsw.cxx
@@ -480,7 +480,7 @@ sal_Bool SwEditRegionDlg::CheckPasswd(CheckBox* pBox)
             {
                 String sNewPasswd( aPasswdDlg.GetPassword() );
                 UNO_NMSPC::Sequence <sal_Int8 > aNewPasswd;
-                SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
+                SvPasswordHelper::GetHashPasswordSHA256( aNewPasswd, 
sNewPasswd );
                 if (SvPasswordHelper::CompareHashPassword(
                         pRepr->GetSectionData().GetPassword(), sNewPasswd))
                 {
@@ -1409,7 +1409,7 @@ IMPL_LINK( SwEditRegionDlg, ChangePasswdHdl, Button *, 
pBox )
                     String sNewPasswd( aPasswdDlg.GetPassword() );
                     if( aPasswdDlg.GetConfirm() == sNewPasswd )
                     {
-                        SvPasswordHelper::GetHashPassword( 
pRepr->GetTempPasswd(), sNewPasswd );
+                        SvPasswordHelper::GetHashPasswordSHA256( 
pRepr->GetTempPasswd(), sNewPasswd );
                     }
                     else
                     {
@@ -1909,7 +1909,7 @@ IMPL_LINK( SwInsertSectionTabPage, ChangePasswdHdl, 
Button *, pButton )
                 String sNewPasswd( aPasswdDlg.GetPassword() );
                 if( aPasswdDlg.GetConfirm() == sNewPasswd )
                 {
-                    SvPasswordHelper::GetHashPassword( m_aNewPasswd, 
sNewPasswd );
+                    SvPasswordHelper::GetHashPasswordSHA256( m_aNewPasswd, 
sNewPasswd );
                 }
                 else
                 {
diff --git a/main/xmloff/inc/xmloff/xmltoken.hxx 
b/main/xmloff/inc/xmloff/xmltoken.hxx
index cbda2bd61c..3776abfe54 100644
--- a/main/xmloff/inc/xmloff/xmltoken.hxx
+++ b/main/xmloff/inc/xmloff/xmltoken.hxx
@@ -1416,6 +1416,7 @@ namespace xmloff { namespace token {
         XML_PROTECT_SIZE,
         XML_PROTECTED,
         XML_PROTECTION_KEY,
+        XML_PROTECTION_KEY_DIGEST_ALGORITHM,
         XML_PRSUBSET,
         XML_PUBLISHER,
         XML_PUNCTUATION_WRAP,
diff --git a/main/xmloff/source/core/xmltoken.cxx 
b/main/xmloff/source/core/xmltoken.cxx
index 69684fed2a..a717deb22c 100644
--- a/main/xmloff/source/core/xmltoken.cxx
+++ b/main/xmloff/source/core/xmltoken.cxx
@@ -1424,6 +1424,7 @@ namespace xmloff { namespace token {
         TOKEN( "size",                            XML_PROTECT_SIZE ),
         TOKEN( "protected",                       XML_PROTECTED ),
         TOKEN( "protection-key",                  XML_PROTECTION_KEY ),
+        TOKEN( "protection-key-digest-algorithm", 
XML_PROTECTION_KEY_DIGEST_ALGORITHM ),
         TOKEN( "prsubset",                        XML_PRSUBSET ),
         TOKEN( "publisher",                       XML_PUBLISHER ),
         TOKEN( "punctuation-wrap",                XML_PUNCTUATION_WRAP ),
diff --git a/main/xmloff/source/text/XMLSectionExport.cxx 
b/main/xmloff/source/text/XMLSectionExport.cxx
index c82a82dff4..78da812f30 100644
--- a/main/xmloff/source/text/XMLSectionExport.cxx
+++ b/main/xmloff/source/text/XMLSectionExport.cxx
@@ -56,6 +56,8 @@
 #include <xmloff/xmlexp.hxx>
 #include <xmloff/xmltkmap.hxx>
 #include "txtflde.hxx"
+#include <svl/PasswordHelper.hxx>
+#include <unotools/saveopt.hxx>
 
 
 
@@ -476,6 +478,14 @@ void XMLSectionExport::ExportRegularSectionStart(
                SvXMLUnitConverter::encodeBase64(aBuffer, aPassword);
                GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTION_KEY,
                                                                 
aBuffer.makeStringAndClear());
+               // ODF 1.2 19.851; without the attribute the key is read as 
SHA-1
+               const OUString aDigest( 
SvPasswordHelper::GetDigestAlgorithmIRI( aPassword ) );
+               if (aDigest.getLength() &&
+                       GetExport().getDefaultVersion() >= 
SvtSaveOptions::ODFVER_012)
+               {
+                       GetExport().AddAttribute(XML_NAMESPACE_TEXT,
+                                                                        
XML_PROTECTION_KEY_DIGEST_ALGORITHM, aDigest);
+               }
        }
 
        // export element

Reply via email to