目錄 / Table of Contents

Class OdfEncryption

Namespace
OdfKit.Core
Assembly
OdfKit.dll

Provides the OdfEncryption API. 提供 OdfEncryption API。

public static class OdfEncryption
Inheritance
OdfEncryption
Inherited Members

Fields

Aes256AlgorithmUri

AES-256 加密演算法的識別 URI。

public const string Aes256AlgorithmUri = "http://www.w3.org/2001/04/xmlenc#aes256-cbc"

Field Value

string

Aes256GcmAlgorithmUri

AES-256-GCM 加密演算法的識別 URI。

public const string Aes256GcmAlgorithmUri = "http://www.w3.org/2009/xmlenc11#aes256-gcm"

Field Value

string

Aes256KeySizeBytes

AES-256 的金鑰長度(位元組);manifest:key-size 缺席時的預設。

public const int Aes256KeySizeBytes = 32

Field Value

int

Argon2idDerivationUri

Argon2id 金鑰衍生函數的識別 URI;與 LibreOffice 25.8+ 的 OpenDocument-v1.4+libreoffice-manifest-schema.rng 一致。

public const string Argon2idDerivationUri = "urn:org:documentfoundation:names:experimental:office:manifest:argon2id"

Field Value

string

Argon2idLegacyDerivationUri

早期 OdfKit 版本寫出的非標準 Argon2id 識別 URI;僅供讀取既有檔案時相容比對。

public const string Argon2idLegacyDerivationUri = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#argon2id"

Field Value

string

Argon2idOdf15DerivationUri

ODF 1.5 草案預計採用的 Argon2id 識別 URI;目前只用於讀取相容。

public const string Argon2idOdf15DerivationUri = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.5#argon2id"

Field Value

string

BlowfishAlgorithmName

ODF 傳統 Blowfish CFB 的規範簡短名稱;manifest:algorithm-name 允許與 URI 等價使用。

public const string BlowfishAlgorithmName = "Blowfish CFB"

Field Value

string

BlowfishAlgorithmUri

ODF 傳統 Blowfish CFB 加密演算法的識別 URI(ODF 1.0~1.4 Part 2 §4.16.1); 回饋寬度依 OpenOffice.org 以來的實作採 64 位元區塊,見 OdfEncryption.Algorithms.cs。

public const string BlowfishAlgorithmUri = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#blowfish"

Field Value

string

BlowfishCbcLegacyAlgorithmUri

早期 OdfKit 版本寫出的非規範 Blowfish CBC 識別 URI;僅供讀取既有檔案時相容比對。

public const string BlowfishCbcLegacyAlgorithmUri = "http://www.w3.org/2001/04/xmldsig-more#blowfish-cbc"

Field Value

string

BlowfishKeySizeBytes

Blowfish 傳統加密的金鑰長度(位元組);manifest:key-size 缺席時的規範預設。

public const int BlowfishKeySizeBytes = 16

Field Value

int

DefaultPbkdf2IterationCount

寫入新文件時採用的 PBKDF2 反覆運算次數。

public const int DefaultPbkdf2IterationCount = 100000

Field Value

int

MaxPbkdf2IterationCount

讀取既有文件時允許的 PBKDF2 反覆運算次數上限,作為 DoS 防線。 實務值需高於現行實作:LibreOffice 26.x 寫入 100,000 次,OWASP 對 PBKDF2-HMAC-SHA1 的現行建議為 1,300,000 次,因此上限訂在 10,000,000。

public const int MaxPbkdf2IterationCount = 10000000

Field Value

int

OneKilobyteChecksumLength

1K 檢查碼所涵蓋的位元組數;ODF 規範定義為壓縮後未加密資料的前 1024 個位元組。

public const int OneKilobyteChecksumLength = 1024

Field Value

int

OpenPgpAlgorithmUri

OpenPGP 加密演算法的識別 URI。

public const string OpenPgpAlgorithmUri = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#openpgp"

Field Value

string

OpenPgpKeyTransportAlgorithmUri

Gets the LibreOffice-compatible OpenPGP key-transport profile identifier. 取得與 LibreOffice 相容的 OpenPGP 金鑰傳送設定檔識別 URI。

public const string OpenPgpKeyTransportAlgorithmUri = "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"

Field Value

string

Remarks

ODF defines manifest:PGPAlgorithm as implementation-defined. This identifier names the interoperable package-key transport profile; entry content encryption is declared separately as AES-256-CBC. ODF 將 manifest:PGPAlgorithm 定義為實作自訂。此識別碼代表可互通的 封裝金鑰傳送設定檔;項目內容加密會另行宣告為 AES-256-CBC。

Sha1OneKilobyteChecksumName

SHA-1/1K 檢查碼的 ODF 規範簡短名稱。

public const string Sha1OneKilobyteChecksumName = "SHA1/1K"

Field Value

string

Sha1OneKilobyteChecksumUri

SHA-1/1K 檢查碼的識別 URI;ODF 1.0~1.1 產出的檔案採用。

public const string Sha1OneKilobyteChecksumUri = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha1-1k"

Field Value

string

Sha256OneKilobyteChecksumUri

SHA-256/1K 檢查碼的識別 URI;ODF 1.2 起建議新實作採用。

public const string Sha256OneKilobyteChecksumUri = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha256-1k"

Field Value

string

Methods

ByteArrayEquals(byte[]?, byte[]?)

Performs byte array equals. 比較兩個位元組陣列是否相等。

public static bool ByteArrayEquals(byte[]? a, byte[]? b)

Parameters

a byte[]

第一個位元組陣列

b byte[]

第二個位元組陣列

Returns

bool

若兩者相等,則為 true ;否則為 false

ComputeHash(byte[], string)

Computes hash. 計算資料的雜湊值;SHA1/1K#sha1-1k#sha256-1k 依 ODF 規範只涵蓋前 1024 個位元組。

public static byte[] ComputeHash(byte[] data, string checksumType)

Parameters

data byte[]

輸入資料的位元組陣列

checksumType string

總和檢查碼的類型(例如 #sha256-1kSHA1/1K、SHA256 或 SHA1)

Returns

byte[]

雜湊值位元組陣列

Decrypt(OdfPackage, string)

Performs the Decrypt operation. 解密指定 ODF 封裝中的所有加密專案。

public static void Decrypt(OdfPackage package, string password)

Parameters

package OdfPackage

要解密的 ODF 封裝執行個體

password string

解密密碼

DecryptEntry(byte[], string, string, string, int, int, byte[], byte[])

Short overload of DecryptEntry that accepts ciphertext, password, algorithmUri, derivationName, keySize, iterationCount, salt, and iv; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 ciphertext、password、algorithmUri、derivationName、keySize、iterationCount、salt 與 iv;其餘可選參數使用預設值並轉呼叫最長 DecryptEntry 多載。

public static byte[] DecryptEntry(byte[] ciphertext, string password, string algorithmUri, string derivationName, int keySize, int iterationCount, byte[] salt, byte[] iv)

Parameters

ciphertext byte[]
password string
algorithmUri string
derivationName string
keySize int
iterationCount int
salt byte[]
iv byte[]

Returns

byte[]

DecryptEntry(byte[], string, string, string, int, int, byte[], byte[], string?)

Short overload of DecryptEntry that accepts ciphertext, password, algorithmUri, derivationName, keySize, iterationCount, salt, iv, and startKeyGenName; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 ciphertext、password、algorithmUri、derivationName、keySize、iterationCount、salt、iv 與 startKeyGenName;其餘可選參數使用預設值並轉呼叫最長 DecryptEntry 多載。

public static byte[] DecryptEntry(byte[] ciphertext, string password, string algorithmUri, string derivationName, int keySize, int iterationCount, byte[] salt, byte[] iv, string? startKeyGenName)

Parameters

ciphertext byte[]
password string
algorithmUri string
derivationName string
keySize int
iterationCount int
salt byte[]
iv byte[]
startKeyGenName string

Returns

byte[]

DecryptEntry(byte[], string, string, string, int, int, byte[], byte[], string?, string?)

Short overload of DecryptEntry that accepts ciphertext, password, algorithmUri, derivationName, keySize, iterationCount, salt, iv, startKeyGenName, and kdfName; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 ciphertext、password、algorithmUri、derivationName、keySize、iterationCount、salt、iv、startKeyGenName 與 kdfName;其餘可選參數使用預設值並轉呼叫最長 DecryptEntry 多載。

public static byte[] DecryptEntry(byte[] ciphertext, string password, string algorithmUri, string derivationName, int keySize, int iterationCount, byte[] salt, byte[] iv, string? startKeyGenName, string? kdfName)

Parameters

ciphertext byte[]
password string
algorithmUri string
derivationName string
keySize int
iterationCount int
salt byte[]
iv byte[]
startKeyGenName string
kdfName string

Returns

byte[]

DecryptEntry(byte[], string, string, string, int, int, byte[], byte[], string?, string?, int)

Short overload of DecryptEntry that accepts ciphertext, password, algorithmUri, derivationName, keySize, iterationCount, salt, iv, startKeyGenName, kdfName, and argon2T; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 ciphertext、password、algorithmUri、derivationName、keySize、iterationCount、salt、iv、startKeyGenName、kdfName 與 argon2T;其餘可選參數使用預設值並轉呼叫最長 DecryptEntry 多載。

public static byte[] DecryptEntry(byte[] ciphertext, string password, string algorithmUri, string derivationName, int keySize, int iterationCount, byte[] salt, byte[] iv, string? startKeyGenName, string? kdfName, int argon2T)

Parameters

ciphertext byte[]
password string
algorithmUri string
derivationName string
keySize int
iterationCount int
salt byte[]
iv byte[]
startKeyGenName string
kdfName string
argon2T int

Returns

byte[]

DecryptEntry(byte[], string, string, string, int, int, byte[], byte[], string?, string?, int, int)

Short overload of DecryptEntry that accepts ciphertext, password, algorithmUri, derivationName, keySize, iterationCount, salt, iv, startKeyGenName, kdfName, argon2T, and argon2M; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 ciphertext、password、algorithmUri、derivationName、keySize、iterationCount、salt、iv、startKeyGenName、kdfName、argon2T 與 argon2M;其餘可選參數使用預設值並轉呼叫最長 DecryptEntry 多載。

public static byte[] DecryptEntry(byte[] ciphertext, string password, string algorithmUri, string derivationName, int keySize, int iterationCount, byte[] salt, byte[] iv, string? startKeyGenName, string? kdfName, int argon2T, int argon2M)

Parameters

ciphertext byte[]
password string
algorithmUri string
derivationName string
keySize int
iterationCount int
salt byte[]
iv byte[]
startKeyGenName string
kdfName string
argon2T int
argon2M int

Returns

byte[]

DecryptEntry(byte[], string, string, string, int, int, byte[], byte[], string?, string?, int, int, int)

Decrypts entry. 解密單一封裝項目。支援 PBKDF2 搭配 AES/Blowfish 以及 Argon2id 搭配 AES-GCM。

public static byte[] DecryptEntry(byte[] ciphertext, string password, string algorithmUri, string derivationName, int keySize, int iterationCount, byte[] salt, byte[] iv, string? startKeyGenName, string? kdfName, int argon2T, int argon2M, int argon2P)

Parameters

ciphertext byte[]

加密的密文資料位元組陣列

password string

解密密碼

algorithmUri string

加密演算法的 XML 識別 URI

derivationName string

金鑰衍生演算法的 XML 識別 URI

keySize int

金鑰大小(以位元組為單位)

iterationCount int

金鑰衍生的反覆運算次數

salt byte[]

金鑰衍生的鹽值(Salt)位元組陣列

iv byte[]

加密的初始向量(IV)位元組陣列

startKeyGenName string

初始金鑰產生的演算法名稱(選填)

kdfName string

金鑰衍生函數的名稱(選填,例如 "argon2id")

argon2T int

Argon2id 的時間複雜度/反覆運算次數(選填)

argon2M int

Argon2id 的記憶體複雜度(單位為 KB,選填)

argon2P int

Argon2id 的平行度/通道數(選填)

Returns

byte[]

解密後的純文字資料位元組陣列

Encrypt(OdfPackage, string)

Short overload of Encrypt that accepts package and password; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 package 與 password;其餘可選參數使用預設值並轉呼叫最長 Encrypt 多載。

public static void Encrypt(OdfPackage package, string password)

Parameters

package OdfPackage
password string

Encrypt(OdfPackage, string, OdfEncryptionAlgorithm)

Performs the Encrypt operation. 加密指定 ODF 封裝中的所有適用專案。

public static void Encrypt(OdfPackage package, string password, OdfEncryptionAlgorithm algorithm)

Parameters

package OdfPackage

要加密的 ODF 封裝執行個體

password string

加密密碼

algorithm OdfEncryptionAlgorithm

加密演算法,預設為 AES-256

EncryptEntry(byte[], string, OdfEncryptionAlgorithm, out byte[], out byte[], out byte[], int)

Encrypts entry. 加密單一封裝項目。支援傳統加密與 AES-GCM 加密,並產生對應的 IV、鹽值與驗證碼。

public static byte[] EncryptEntry(byte[] plaintext, string password, OdfEncryptionAlgorithm algorithm, out byte[] iv, out byte[] salt, out byte[] checksum, int iterationCount = 100000)

Parameters

plaintext byte[]

待加密的純文字資料位元組陣列

password string

加密密碼

algorithm OdfEncryptionAlgorithm

加密演算法類型

iv byte[]

輸出參數,接收隨機產生的初始向量(IV)位元組陣列

salt byte[]

輸出參數,接收隨機產生的鹽值(Salt)位元組陣列

checksum byte[]

輸出參數,接收加密後計算出的驗證碼(Checksum)位元組陣列

iterationCount int

金鑰衍生的反覆運算次數(預設為 DefaultPbkdf2IterationCount

Returns

byte[]

加密後的密文資料位元組陣列

Pbkdf2(byte[], byte[], int, int, string)

Performs pbkdf 2. 自訂實作以金鑰為基礎的金鑰衍生函式 PBKDF2,支援 SHA-1 與 SHA-256,確保跨平台行為一致。

public static byte[] Pbkdf2(byte[] password, byte[] salt, int iterations, int keyLength, string hashName)

Parameters

password byte[]

密碼位元組陣列

salt byte[]

鹽值位元組陣列

iterations int

反覆運算次數

keyLength int

衍生的金鑰長度

hashName string

雜湊演算法名稱

Returns

byte[]

衍生的金鑰位元組陣列