How to instantiate algorithms in Pointy Castle
masterPointy Castle algorithms must be instantiated and then initialized with their specific parameters. There are two primary ways to create algorithm objects:
1. Using the Registry (Recommended for simplicity)
Use high-level class factories (like Digest, Mac, KeyDerivator, etc.) and provide an algorithm name string. This is convenient because the registry automatically handles complex algorithms that require multiple underlying implementation classes (e.g., "SHA-1/HMAC/PBKDF2").
2. Without the Registry (Recommended for reducing binary size)
Instantiate each implementation class directly using its constructor. For complex algorithms, you must manually instantiate and combine the individual components (e.g., passing a SHA256Digest into an HMac constructor).
Note on binary size: Using the registry imports all algorithms by default, which increases the compiled size of your program. To minimize size, instantiate classes directly via constructors.
// Using the Registry
final sha256 = Digest("SHA-256");
final hmacSha256 = Mac("SHA-256/HMAC");
final derivator = KeyDerivator("SHA-1/HMAC/PBKDF2");
// Without the Registry
final sha256 = SHA256Digest();
final hmacSha256 = HMac(SHA256Digest(), 64);
final derivator = PBKDF2KeyDerivator(HMac(SHA256Digest(), 64));