Interface CryptoPolicy<S extends ContextSpec, K extends Key>
- Type Parameters:
S- context specification typeK- key type
public interface CryptoPolicy<S extends ContextSpec, K extends Key>
A strategy interface for validating cryptographic keys, usages, and
specifications before contexts are created.
A CryptoPolicy is consulted by higher layers (such as
CryptoAlgorithms) to enforce organizational or
security-specific rules. Policies may range from permissive (accept
everything) to strict (require minimum key sizes, algorithm whitelisting,
usage separation, etc.).
Design goals
- Allow central enforcement of key strength and usage constraints.
- Support extensibility without hardcoding checks into algorithms.
- Enable application-specific security postures while sharing the same underlying primitives.
Typical usage
ZeroEchoSession session = new ZeroEchoSession()
.withPolicy(CryptoPolicy.minStrength(128));
// Later, when creating a context:
EncryptionContext ctx = session.createContext("AES", KeyUsage.ENCRYPT, secretKey);
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends ContextSpec, K extends Key>
CryptoPolicy<S, K> minStrength(int minBits) Returns a policy that enforces a minimum estimated key strength.static <S extends ContextSpec, K extends Key>
CryptoPolicy<S, K> Returns a permissive policy that accepts all keys, roles, and specs without validation.voidValidates an algorithm identifier, role, key, and spec.
-
Method Details
-
validate
Validates an algorithm identifier, role, key, and spec.Implementations should throw an unchecked exception (typically
IllegalArgumentException) if the combination violates policy.- Parameters:
id- canonical algorithm identifierrole- intended key usage rolekey- cryptographic key (may beNullKeyfor unkeyed flows)spec- optional context specification; may benull- Throws:
IllegalArgumentException- if the parameters are not permitted by the policy
-
permissive
Returns a permissive policy that accepts all keys, roles, and specs without validation.This is the default when no explicit policy is configured.
- Type Parameters:
S- context specification typeK- key type- Returns:
- a permissive
CryptoPolicy
-
minStrength
Returns a policy that enforces a minimum estimated key strength.Key strength is estimated in bits using
SecurityStrengthAdvisor.estimateBits(String, Key). If the strength is belowminBits, validation fails withIllegalArgumentException.- Type Parameters:
S- context specification typeK- key type- Parameters:
minBits- minimum acceptable estimated key strength, in bits- Returns:
- a
CryptoPolicythat enforces minimum key strength - Throws:
IllegalArgumentException- ifminBitsis negative
-