암호화 및 보안
PDF Oxide는 업계 표준 알고리즘을 사용해 비밀번호와 권한으로 PDF를 암호화할 수 있습니다. 사용자 비밀번호(문서를 열 때 필요), 소유자 비밀번호(전체 액세스에 필요), 그리고 인쇄·복사·수정을 세밀하게 제어하는 권한을 설정할 수 있습니다.
바인딩 지원 현황. 암호화된 PDF 열기는 모든 바인딩에서 작동합니다(Python에서는
password=, Rust에서는PdfDocument.open_with_password, WASM에서는authenticate(), Go/C#PdfDocument에서는Authenticate, C#에서는OpenWithPassword). 암호화 출력 생성(save_encrypted/saveEncryptedToBytes)은 Python, Rust, WASM, Go(DocumentEditor.SaveEncrypted)에서 사용할 수 있습니다. C#DocumentEditor는 현재SaveEncrypted를 제공하지 않으므로, C# 워크플로에서 암호화 출력을 생성하려면 Rust CLI(pdf-oxide encrypt)나 Go/Python 단계를 사용하세요.
알고리즘 지원
| 알고리즘 | 읽기 | 쓰기 | 비고 |
|---|---|---|---|
| RC4 (40/128비트) | 예 | 예 | 레거시; 호환성 목적으로만 사용 |
| AES-128 (V=4, R=4) | 예 | 예 | PDF 1.6+ 기본값 |
| AES-256 (V=5, R=6) | 예 | 예 | PDF 2.0; 비압축 객체 문자열 복호화, 버튼 위젯 /MK /CA 캡션, 올바른 Algorithm 2.B 종료 포함 |
AES-256은 완전한 엔드투엔드 지원을 제공합니다: 열기, 인증, 양식 값 읽기, 암호화 출력 저장이 모두 가능합니다. ObjStm / XRef 스트림은 ISO 32000-2 §7.6.3에 따라 암호화되지 않습니다. 지연된 authenticate() 호출 후에는 객체 캐시가 올바르게 무효화되어, 인증 전에 읽힌 콘텐츠가 올바른 키로 재파싱됩니다.
빠른 시작: 암호화하여 저장
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")?;
Go
package main
import (
"log"
pdfoxide "github.com/yfedoseev/pdf_oxide/go"
)
func main() {
editor, err := pdfoxide.OpenEditor("input.pdf")
if err != nil { log.Fatal(err) }
defer editor.Close()
_ = editor.SetTitle("Confidential Report")
// Encrypt with user and owner passwords (AES-256)
if err := editor.SaveEncrypted("protected.pdf", "user123", "owner456"); err != nil {
log.Fatal(err)
}
}
C++
#include <pdf_oxide/pdf_oxide.hpp>
auto editor = pdf_oxide::DocumentEditor::open("input.pdf");
// Encrypt with user and owner passwords (AES-256)
editor.save_encrypted("protected.pdf", "user123", "owner456");
Swift
import PdfOxide
let editor = try DocumentEditor.openEditor("input.pdf")
// Encrypt with user and owner passwords (AES-256)
try editor.saveEncrypted("protected.pdf", userPassword: "user123", ownerPassword: "owner456")
Dart
import 'package:pdf_oxide/pdf_oxide.dart';
final editor = DocumentEditor.open('input.pdf');
// Encrypt with user and owner passwords (AES-256)
editor.saveEncrypted('protected.pdf', 'user123', 'owner456');
editor.close();
R
library(pdfoxide)
editor <- pdf_editor_open("input.pdf")
# Encrypt with user and owner passwords (AES-256)
pdf_editor_save_encrypted(editor, "protected.pdf", "user123", "owner456")
Julia
using PdfOxide
editor = open_editor("input.pdf")
# Encrypt with user and owner passwords (AES-256)
save_encrypted(editor, "protected.pdf", "user123", "owner456")
Zig
const pdf_oxide = @import("pdf_oxide");
var editor = try pdf_oxide.DocumentEditor.openEditor("input.pdf");
defer editor.deinit();
// Encrypt with user and owner passwords (AES-256)
try editor.saveEncrypted("protected.pdf", "user123", "owner456");
Objective-C
#import "POXPdfOxide.h"
NSError *err = nil;
POXDocumentEditor *editor = [POXDocumentEditor openEditor:@"input.pdf" error:&err];
// Encrypt with user and owner passwords (AES-256)
[editor saveEncryptedToPath:@"protected.pdf"
userPassword:@"user123"
ownerPassword:@"owner456"
error:&err];
Elixir
{:ok, editor} = PdfOxide.open_editor("input.pdf")
# Encrypt with user and owner passwords (AES-256)
:ok = PdfOxide.editor_save_encrypted(editor, "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 매개변수
| 매개변수 | 타입 | 기본값 | 설명 |
|---|---|---|---|
path |
str |
필수 | 출력 파일 경로 |
user_password |
str |
필수 | 열기 비밀번호 (빈 문자열 = 비밀번호 없음) |
owner_password |
str |
None |
전체 액세스 비밀번호 (기본값: 사용자 비밀번호와 동일) |
allow_print |
bool |
True |
인쇄 허용 |
allow_copy |
bool |
True |
텍스트/그래픽 복사 허용 |
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; // Allow printing 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 필드
| 필드 | 타입 | 설명 |
|---|---|---|
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의 save_encrypted() 또는 Pdf API 사용 시 AES-256이 기본값입니다.
권한 (Permissions)
Permissions 구조체는 사용자 비밀번호로 문서를 열었을 때 허용되는 작업을 제어합니다.
use pdf_oxide::editor::Permissions;
// Allow everything
let all = Permissions::all();
// Restrict everything
let readonly = Permissions::read_only();
Permissions 필드
| 필드 | 타입 | 기본값 (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; // Allow printing
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);
Go
doc, _ := pdfoxide.Open("protected.pdf")
defer doc.Close()
if _, err := doc.Authenticate("user123"); err != nil { log.Fatal(err) }
text, _ := doc.ExtractText(0)
fmt.Println(text)
C#
using var doc = PdfDocument.OpenWithPassword("protected.pdf", "user123");
Console.WriteLine(doc.ExtractText(0));
C++
#include <pdf_oxide/pdf_oxide.hpp>
#include <iostream>
auto doc = pdf_oxide::Document::open_with_password("protected.pdf", "user123");
std::cout << doc.extract_text(0) << std::endl;
Swift
import PdfOxide
let doc = try Document.openWithPassword("protected.pdf", password: "user123")
print(try doc.extractText(0))
Dart
import 'package:pdf_oxide/pdf_oxide.dart';
final doc = PdfDocument.openWithPassword('protected.pdf', 'user123');
print(doc.extractText(0));
doc.close();
R
library(pdfoxide)
doc <- pdf_open_with_password("protected.pdf", "user123")
cat(pdf_extract_text(doc, 0))
Julia
using PdfOxide
doc = open_with_password("protected.pdf", "user123")
println(extract_text(doc, 0))
Zig
const std = @import("std");
const pdf_oxide = @import("pdf_oxide");
const a = std.heap.page_allocator;
var doc = try pdf_oxide.Document.openWithPassword("protected.pdf", "user123");
defer doc.deinit();
const text = try doc.extractText(a, 0);
std.debug.print("{s}\n", .{text});
Objective-C
#import "POXPdfOxide.h"
NSError *err = nil;
POXDocument *doc = [POXDocument openWithPassword:@"protected.pdf" password:@"user123" error:&err];
NSLog(@"%@", [doc extractText:0 error:&err]);
Elixir
{:ok, doc} = PdfOxide.open_with_password("protected.pdf", "user123")
{:ok, text} = PdfOxide.extract_text(doc, 0)
IO.puts(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", # Owner password 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)?;
아래의 전체 표면 바인딩은 AES-256 암호화와 전체 권한으로 출력을 저장합니다. Python/WASM/Rust에서 제공하는 개별 플래그 기반의 권한 제어는 제공하지 않습니다. 저장 전에 에디터의
set_producer로/Info메타데이터를 설정하세요.
C++
#include <pdf_oxide/pdf_oxide.hpp>
auto editor = pdf_oxide::DocumentEditor::open("report.pdf");
editor.set_producer("Finance Team");
// Save with AES-256 encryption (no open password, owner password for full access)
editor.save_encrypted("report-protected.pdf", "", "admin2025");
Swift
import PdfOxide
let editor = try DocumentEditor.openEditor("report.pdf")
try editor.setProducer("Finance Team")
// Save with AES-256 encryption (no open password, owner password for full access)
try editor.saveEncrypted("report-protected.pdf", userPassword: "", ownerPassword: "admin2025")
Dart
import 'package:pdf_oxide/pdf_oxide.dart';
final editor = DocumentEditor.open('report.pdf');
editor.setProducer('Finance Team');
// Save with AES-256 encryption (no open password, owner password for full access)
editor.saveEncrypted('report-protected.pdf', '', 'admin2025');
editor.close();
R
library(pdfoxide)
editor <- pdf_editor_open("report.pdf")
pdf_editor_set_producer(editor, "Finance Team")
# Save with AES-256 encryption (no open password, owner password for full access)
pdf_editor_save_encrypted(editor, "report-protected.pdf", "", "admin2025")
Julia
using PdfOxide
editor = open_editor("report.pdf")
set_producer(editor, "Finance Team")
# Save with AES-256 encryption (no open password, owner password for full access)
save_encrypted(editor, "report-protected.pdf", "", "admin2025")
Zig
const pdf_oxide = @import("pdf_oxide");
var editor = try pdf_oxide.DocumentEditor.openEditor("report.pdf");
defer editor.deinit();
try editor.setProducer("Finance Team");
// Save with AES-256 encryption (no open password, owner password for full access)
try editor.saveEncrypted("report-protected.pdf", "", "admin2025");
Objective-C
#import "POXPdfOxide.h"
NSError *err = nil;
POXDocumentEditor *editor = [POXDocumentEditor openEditor:@"report.pdf" error:&err];
[editor setProducer:@"Finance Team" error:&err];
// Save with AES-256 encryption (no open password, owner password for full access)
[editor saveEncryptedToPath:@"report-protected.pdf"
userPassword:@""
ownerPassword:@"admin2025"
error:&err];
Elixir
{:ok, editor} = PdfOxide.open_editor("report.pdf")
:ok = PdfOxide.set_producer(editor, "Finance Team")
# Save with AES-256 encryption (no open password, owner password for full access)
:ok = PdfOxide.editor_save_encrypted(editor, "report-protected.pdf", "", "admin2025")
다른 설정으로 재암호화
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 메서드
| 메서드 | 반환값 | 설명 |
|---|---|---|
save_encrypted(path, user_pw, owner_pw) |
Result<()> |
AES-256과 전체 권한으로 저장 |
save_with_encryption(path, config) |
Result<()> |
사용자 지정 암호화 설정으로 저장 |
DocumentEditor / EditableDocument 메서드
| 메서드 | 반환값 | 설명 |
|---|---|---|
save(path) |
Result<()> |
전체 재작성으로 저장 (암호화 없음) |
save_with_options(path, options) |
Result<()> |
사용자 지정 옵션으로 저장 |
설정 타입
| 타입 | 설명 |
|---|---|
EncryptionConfig |
사용자/소유자 비밀번호, 알고리즘, 권한 |
EncryptionAlgorithm |
Aes256, Aes128, Rc4_128, Rc4_40 |
Permissions |
세밀한 액세스 제어 플래그 |
SaveOptions |
전체 재작성, 증분 업데이트 또는 암호화 저장 |
관련 페이지
- 편집 개요 – 열기, 메타데이터, 저장 워크플로
- 양식 필드 편집 – 권한으로 양식 편집 제한
- 내용 삭제 (Redaction) – 암호화 전 내용 삭제
- 페이지 작업 – 최종 암호화 전 페이지 준비