🍋
Menu
Security

Public Key

Public Key Cryptography

A cryptographic system using paired keys where the public key encrypts and only the private key can decrypt.

技术细节

Public Key's security rests on the computational difficulty of factoring large semiprimes. Key sizes: 2048-bit is the current minimum, 4096-bit is recommended for long-term security. RSA is ~1000x slower than AES, so it's typically used to encrypt a symmetric session key (hybrid encryption). RSA signing uses the private key; verification uses the public key — the reverse of encryption. OAEP padding (PKCS#1 v2) is required; the older PKCS#1 v1.5 padding has known vulnerabilities (Bleichenbacher's attack).

示例

```javascript
// AES-256-GCM encryption (Web Crypto API)
const key = await crypto.subtle.generateKey(
  { name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']
);
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt(
  { name: 'AES-GCM', iv },
  key,
  new TextEncoder().encode('secret message')
);
```

相关工具

相关术语