암호화 & 보안
PDF Oxide는 업계 표준 알고리즘을 사용하여 비밀번호와 권한으로 PDF를 암호화하는 기능을 제공합니다. 사용자 비밀번호(문서 열기에 필요), 소유자 비밀번호(전체 접근에 필요), 인쇄, 복사, 수정을 제어하는 세밀한 권한을 설정할 수 있습니다.
빠른 시작: 암호화하여 저장
Python
from pdf_oxide import PdfDocument
doc = PdfDocument("input.pdf")
doc.set_title("Confidential Report")
# Encrypt with user and owner passwords
doc.save_encrypted("protected.pdf", "user123", "owner456")
WASM
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
doc.setTitle("Confidential Report");
// Encrypt with user and owner passwords (all permissions enabled)
const output = doc.saveEncryptedToBytes(
"user123", "owner456", true, true, true, true
);
doc.free();
Rust
use pdf_oxide::api::Pdf;
let mut doc = Pdf::open("input.pdf")?;
// Simple encryption with user and owner passwords
doc.save_encrypted("protected.pdf", "user123", "owner456")?;
커스텀 권한으로 암호화
Python
save_encrypted 메서드는 키워드 인수로 권한 플래그를 받습니다.
from pdf_oxide import PdfDocument
doc = PdfDocument("input.pdf")
# View-only: no printing, copying, or modifying
doc.save_encrypted(
"readonly.pdf",
"viewpass",
"adminpass",
allow_print=False,
allow_copy=False,
allow_modify=False,
allow_annotate=False,
)
# Allow only printing
doc.save_encrypted(
"print-only.pdf",
"", # No open password required
"adminpass",
allow_print=True,
allow_copy=False,
allow_modify=False,
allow_annotate=False,
)
Python save_encrypted 매개변수
| Parameter | 타입 | 기본값 | 설명 |
|---|---|---|---|
path |
str |
required | Output file path |
user_password |
str |
required | 열기 비밀번호(빈 값 = 비밀번호 없음) |
owner_password |
str |
None |
전체 접근 비밀번호(기본값: 사용자 비밀번호) |
allow_print |
bool |
True |
인쇄 허용 |
allow_copy |
bool |
True |
복사 허용 text/graphics |
allow_modify |
bool |
True |
문서 수정 허용 |
allow_annotate |
bool |
True |
주석 추가 허용 |
WASM
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
// View-only: no printing, copying, or modifying
const readonly = doc.saveEncryptedToBytes(
"viewpass", "adminpass", false, false, false, false
);
// Allow only printing (empty user password = no open password)
const printOnly = doc.saveEncryptedToBytes(
"", "adminpass", true, false, false, false
);
doc.free();
Rust
암호화 설정을 완전히 제어하려면 EncryptionConfig와 SaveOptions를 사용합니다.
use pdf_oxide::api::Pdf;
use pdf_oxide::editor::{
EncryptionConfig, EncryptionAlgorithm, Permissions, SaveOptions,
};
let mut doc = Pdf::open("input.pdf")?;
// Build permissions
let mut perms = Permissions::read_only();
perms.print = true; // 인쇄 허용 only
// Build encryption config
let config = EncryptionConfig::new("user123", "owner456")
.with_algorithm(EncryptionAlgorithm::Aes256)
.with_permissions(perms);
// Save with encryption
doc.save_with_encryption("protected.pdf", config)?;
EncryptionConfig
EncryptionConfig 구조체는 모든 암호화 매개변수를 제어합니다.
use pdf_oxide::editor::{EncryptionConfig, EncryptionAlgorithm, Permissions};
let config = EncryptionConfig {
user_password: "user123".to_string(),
owner_password: "owner456".to_string(),
algorithm: EncryptionAlgorithm::Aes256,
permissions: Permissions::all(),
};
또는 빌더 패턴을 사용합니다:
let config = EncryptionConfig::new("user123", "owner456")
.with_algorithm(EncryptionAlgorithm::Aes128)
.with_permissions(Permissions::read_only());
EncryptionConfig Fields
| Field | 타입 | 설명 |
|---|---|---|
user_password |
String |
문서 열기에 필요한 비밀번호 |
owner_password |
String |
전체 접근 및 보안 변경을 위한 비밀번호 |
algorithm |
EncryptionAlgorithm |
사용할 암호화 알고리즘 |
permissions |
Permissions |
접근 제어 플래그 |
암호화 알고리즘
| 알고리즘 | 설명 |
|---|---|
EncryptionAlgorithm::Aes256 |
AES-256 (가장 강력, 권장) |
EncryptionAlgorithm::Aes128 |
AES-128 |
EncryptionAlgorithm::Rc4_128 |
RC4 128비트 (레거시 호환) |
EncryptionAlgorithm::Rc4_40 |
RC4 40비트 (레거시, 취약) |
Python 또는 Pdf API에서 save_encrypted()를 사용할 때 AES-256이 기본값입니다.
권한
Permissions 구조체는 사용자 비밀번호로 문서를 열 때 허용되는 작업을 제어합니다.
use pdf_oxide::editor::Permissions;
// Allow everything
let all = Permissions::all();
// Restrict everything
let readonly = Permissions::read_only();
Permissions Fields
| Field | 타입 | 기본값 (all) | 기본값 (read_only) | 설명 |
|---|---|---|---|---|
print |
bool |
true |
false |
인쇄 허용 |
print_high_quality |
bool |
true |
false |
고품질 인쇄 허용 |
modify |
bool |
true |
false |
콘텐츠 수정 허용 |
copy |
bool |
true |
false |
텍스트/그래픽 복사 허용 |
annotate |
bool |
true |
false |
주석 추가 허용 |
fill_forms |
bool |
true |
false |
양식 필드 채우기 허용 |
accessibility |
bool |
true |
true |
접근성 추출 허용 |
assemble |
bool |
true |
false |
페이지 어셈블리 작업 허용 |
커스텀 권한
let mut perms = Permissions::read_only();
perms.print = true; // 인쇄 허용
perms.fill_forms = true; // Allow filling forms
perms.accessibility = true; // Always allow for compliance
SaveOptions
문서가 작성되는 방식을 완전히 제어하려면 SaveOptions를 사용합니다.
use pdf_oxide::editor::{SaveOptions, EncryptionConfig};
// Full rewrite (default)
let opts = SaveOptions::full_rewrite();
// Incremental update (faster, preserves structure)
let opts = SaveOptions::incremental();
// With encryption
let config = EncryptionConfig::new("user", "owner");
let opts = SaveOptions::with_encryption(config);
암호화된 PDF 열기
Python
문서를 열 때 비밀번호를 전달하세요.
from pdf_oxide import PdfDocument
doc = PdfDocument("protected.pdf", password="user123")
text = doc.extract_text(0)
print(text)
Rust
use pdf_oxide::PdfDocument;
let doc = PdfDocument::open_with_password("protected.pdf", "user123")?;
let text = doc.extract_text(0)?;
println!("{}", text);
전체 암호화 워크플로
Python
from pdf_oxide import PdfDocument
# Open and modify
doc = PdfDocument("report.pdf")
doc.set_title("Confidential Report")
doc.set_author("Finance Team")
# Save with view-only restrictions
doc.save_encrypted(
"report-protected.pdf",
"", # No password to open
"admin2025", # 소유자 비밀번호 for full access
allow_print=True,
allow_copy=False,
allow_modify=False,
)
WASM
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
doc.setTitle("Confidential Report");
doc.setAuthor("Finance Team");
// Save with view-only restrictions (no open password, print allowed)
const output = doc.saveEncryptedToBytes(
"", "admin2025", true, false, false, false
);
doc.free();
Rust
use pdf_oxide::api::Pdf;
use pdf_oxide::editor::{
DocumentEditor, EditableDocument,
EncryptionConfig, EncryptionAlgorithm, Permissions, SaveOptions,
};
// Open and modify
let mut doc = Pdf::open("report.pdf")?;
{
let editor = doc.editor().unwrap();
editor.set_title("Confidential Report");
editor.set_author("Finance Team");
}
// Configure encryption
let permissions = Permissions {
print: true,
print_high_quality: true,
modify: false,
copy: false,
annotate: false,
fill_forms: true,
accessibility: true,
assemble: false,
};
let config = EncryptionConfig::new("", "admin2025")
.with_algorithm(EncryptionAlgorithm::Aes256)
.with_permissions(permissions);
doc.save_with_encryption("report-protected.pdf", config)?;
다른 설정으로 재암호화
Rust
use pdf_oxide::editor::{DocumentEditor, EditableDocument, EncryptionConfig, SaveOptions};
// Open with current password
let mut editor = DocumentEditor::open("old-protected.pdf")?;
// Save with new encryption
let config = EncryptionConfig::new("newuser", "newowner");
let options = SaveOptions::with_encryption(config);
editor.save_with_options("re-encrypted.pdf", options)?;
전체 API 레퍼런스
Pdf 메서드s
| 메서드 | 반환값 | 설명 |
|---|---|---|
save_encrypted(path, user_pw, owner_pw) |
Result<()> |
Save with AES-256 and full permissions |
save_with_encryption(path, config) |
Result<()> |
Save with custom encryption config |
DocumentEditor / EditableDocument 메서드s
| 메서드 | 반환값 | 설명 |
|---|---|---|
save(path) |
Result<()> |
Save with full rewrite (no encryption) |
save_with_options(path, options) |
Result<()> |
Save with custom options |
구성 타입
| 타입 | 설명 |
|---|---|
EncryptionConfig |
사용자/소유자 비밀번호, 알고리즘, 권한 |
EncryptionAlgorithm |
Aes256, Aes128, Rc4_128, Rc4_40 |
Permissions |
세밀한 접근 제어 플래그 |
SaveOptions |
전체 재작성, 증분 또는 암호화 저장 |
관련 페이지
- Editing Overview – opening, metadata, and save workflow
- Form Field Editing – restrict form editing with permissions
- Redaction – redact content before encrypting
- Page Operations – prepare pages before final encryption