Class RsaEncSpec
java.lang.Object
zeroecho.core.alg.rsa.RsaEncSpec
- All Implemented Interfaces:
Describable, ContextSpec
Specification of RSA encryption parameters including padding mode, hash
function, and optional OAEP label.
This spec is used with RsaCipherContext to configure how RSA
encryption and decryption should be performed. It supports two padding
schemes:
RsaEncSpec.Padding.OAEPwith a configurable hash function and optional label (as defined in PKCS#1 v2.2).RsaEncSpec.Padding.PKCS1V15(PKCS#1 v1.5 padding), without hash or label.
Construction
Use the static factories to create a spec:// OAEP with SHA-256
RsaEncSpec oaep = RsaEncSpec.oaep(RsaEncSpec.Hash.SHA256);
// PKCS#1 v1.5
RsaEncSpec pkcs1 = RsaEncSpec.pkcs1v15();
// OAEP with SHA-384 and custom UTF-8 label
RsaEncSpec labeled = RsaEncSpec.oaep(RsaEncSpec.Hash.SHA384)
.withLabelUtf8("context");
Instances are immutable. Methods withLabel(byte[]) and
withLabelUtf8(String) return new copies with the given label.
Security notes
- OAEP with SHA-256 or stronger is recommended; PKCS#1 v1.5 is retained only for interoperability and should be avoided for new designs.
- Labels in OAEP can provide domain separation but are optional; most applications leave them unset.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHash algorithms usable within OAEP padding.static enumSupported RSA padding schemes. -
Method Summary
Modifier and TypeMethodDescriptionReturns a short human-readable description of this spec.hash()Returns the hash function used in OAEP.byte[]label()Returns the OAEP label as a defensive copy.static RsaEncSpecCreates an OAEP spec with the given hash function and no label.padding()Returns the padding scheme.static RsaEncSpecpkcs1v15()Creates a PKCS#1 v1.5 spec.withLabel(byte[] l) Returns a copy of this spec with the given OAEP label.Returns a copy of this spec with the given UTF-8 OAEP label.
-
Method Details
-
oaep
Creates an OAEP spec with the given hash function and no label.- Parameters:
h- hash function for OAEP- Returns:
- new
RsaEncSpecfor OAEP
-
pkcs1v15
Creates a PKCS#1 v1.5 spec.- Returns:
- new
RsaEncSpecfor PKCS#1 v1.5
-
withLabel
Returns a copy of this spec with the given OAEP label.- Parameters:
l- label bytes (cloned); may be null to clear- Returns:
- new
RsaEncSpecwith the same padding/hash and new label
-
withLabelUtf8
Returns a copy of this spec with the given UTF-8 OAEP label.- Parameters:
s- label string encoded in UTF-8; may be null to clear- Returns:
- new
RsaEncSpecwith the same padding/hash and new label
-
padding
-
hash
Returns the hash function used in OAEP.- Returns:
- OAEP hash function, or null if padding is PKCS#1 v1.5
-
label
public byte[] label()Returns the OAEP label as a defensive copy.- Returns:
- cloned OAEP label, or null if none
-
description
Returns a short human-readable description of this spec.Examples:
"PKCS1v1.5""OAEP(SHA256,label=8B)"
- Specified by:
descriptionin interfaceDescribable- Returns:
- description string
-