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

Argon2idDerivationUri

Argon2id 金鑰衍生函數的識別 URI。

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

Field Value

string

BlowfishAlgorithmUri

Blowfish 加密演算法的識別 URI。

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

Field Value

string

OpenPgpAlgorithmUri

OpenPGP 加密演算法的識別 URI。

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

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. 計算資料的雜湊值。

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

Parameters

data byte[]

輸入資料的位元組陣列

checksumType string

總和檢查碼的類型(例如 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 = 50000)

Parameters

plaintext byte[]

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

password string

加密密碼

algorithm OdfEncryptionAlgorithm

加密演算法類型

iv byte[]

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

salt byte[]

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

checksum byte[]

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

iterationCount int

金鑰衍生的反覆運算次數(預設為 50,000 次)

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[]

衍生的金鑰位元組陣列