Changing Between Blowfish and AES Encryption

From Apache OpenOffice Wiki
< User:TJFrazier
Revision as of 23:03, 19 April 2012 by TJFrazier (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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