Changing Between Blowfish and AES Encryption

From Apache OpenOffice Wiki
Jump to: navigation, search

Who needs this macro

  • If you do not use file passwords, or use them only to protect your own files on one computer, then you do not need this macro.
  • If you share password-protected files with other users and/or other computers, you may need this macro.
  • If you want or need to use the new encryption feature described below, you will need to activate the feature; this macro is one of several ways to do that.
  • If you want to switch back and forth between encryption methods, then this macro is probably the most convenient way to do that, for the time being.


Files saved with a password are further protected by encryption. In 3.3 and earlier versions, and in some other ODF editors, the methods of key application and encryption are known as “SHA1 / Blowfish”. Apache OpenOffice 3.4 also offers a new pair of methods, known as “SHA256 / AES”. Because the new methods may be required by some organizations, the capability was added as soon as possible, and without the normal GUI enhancements.
The following macro is provided as a workaround for AOO 3.4, and possibly for subsequent versions, until the GUI is implemented. The changes it makes are persistent, and will remain in effect until a subsequent change. All file types (password-protected) will be stored with the selected encryption.


AOO 3.4 will automatically select the proper encryption for opening existing files. However, a subsequent save will use the globally chosen method, rather than the original. 3.3, and other editors of similar vintage, will not open files encrypted with "SHA256 / AES". Instead, they will report a read error.

Documentation note.png Do not run this macro under 3.3. It will not work, and may crash the program.
Documentation caution.png Changes made by this macro will not take effect until AOO is restarted.

Macro Source

Option Explicit
Sub EncryptionToggle
REM Toggle encryption mode between SHA1/Blowfish and SHA256/AES.
REM Author: T.J. Frazier  2012-April
REM License: ALv2
Const sPathODF as String = "/org.openoffice.Office.Common/Save/ODF"
Const sAES as String = "SHA256 / AES"
Const sBlow as String = "SHA1 / Blowfish"
Dim Args(0) as New	'params for update
Args(0).Name = "nodePath"
Args(0).Value = sPathODF
Dim bNew as Boolean			'New option value
Dim bOld as Boolean			'Previous option setting
Dim iAnswer as Integer		'Msgbox reply
Dim oConfig as Object		'Partial configuration data
Dim oProvider as Object		'Configuration Provider
Dim s as String				'scratch
Dim sWas as String			'describes previous option
Dim sNew as String			'describes new option
  s = ""
  oProvider = createUnoService(s)
  s = ""
  oConfig = oProvider.createInstanceWithArguments(s, Args())
  bOld = oConfig.UseBlowfishInODF12
  If bOld Then	'Blowfish is current
    sWas = sBlow
    sNew = sAES
  Else			'AES is current
    sWas = sAES
    sNew = sBlow
  EndIf 'Blowfish active
  iAnswer = Msgbox( "Current encryption is " & sWas & "." & chr(13) _
    & "Change to " & sNew & " instead?" & chr(13), _
    "Change File Encryption" )
  If iAnswer = IDYES Then
    bNew = Not bOld
    oConfig.UseBlowfishInODF12 = bNew
    oConfig.UseSHA1InODF12 = bNew
    Msgbox "When you drop and restart OpenOffice (including the Quickstarter)," _
      & "this change will take effect.", MB_OK + MB_ICONINFORMATION, _
      "File Encryption Changed to " & sNew
  EndIf 'user said Yes
End Sub 'EncryptionToggle
Personal tools