public final class Signature
- Object
- Signature
Digital signature creation and verification. Backed by the platform’s
native crypto provider – works with PublicKey / PrivateKey objects
from this package.
Example: sign with RSA-SHA-256 and verify
KeyPair kp = KeyGenerator.rsa(2048);
byte[] sig = Signature.sign(Signature.SHA256_WITH_RSA, kp.getPrivateKey(), data);
boolean ok = Signature.verify(Signature.SHA256_WITH_RSA, kp.getPublicKey(), data, sig);
Fields
public static final String SHA256_WITH_RSA = "SHA256withRSA" | SHA256withRSA – RSA PKCS#1 v1.5 with SHA-256. |
public static final String SHA384_WITH_RSA = "SHA384withRSA" | SHA384withRSA – RSA PKCS#1 v1.5 with SHA-384. |
public static final String SHA512_WITH_RSA = "SHA512withRSA" | SHA512withRSA – RSA PKCS#1 v1.5 with SHA-512. |
public static final String SHA256_WITH_ECDSA = "SHA256withECDSA" | SHA256withECDSA – ECDSA with SHA-256 (P-256 curve). |
public static final String SHA384_WITH_ECDSA = "SHA384withECDSA" | SHA384withECDSA – ECDSA with SHA-384 (P-384 curve). |
public static final String SHA512_WITH_ECDSA = "SHA512withECDSA" | SHA512withECDSA – ECDSA with SHA-512 (P-521 curve). |
Methods
public static byte[] sign(String algorithm, PrivateKey key, byte[] data) | Signs data with the given algorithm and private key. |
public static boolean verify(String algorithm, PublicKey key, byte[] data, byte[] signature) | Verifies signature against data using the given algorithm and public key. |
Inherited methods
Field details
SHA256_WITH_RSA
public static final String SHA256_WITH_RSA = "SHA256withRSA"SHA256withRSA – RSA PKCS#1 v1.5 with SHA-256.SHA384_WITH_RSA
public static final String SHA384_WITH_RSA = "SHA384withRSA"SHA384withRSA – RSA PKCS#1 v1.5 with SHA-384.SHA512_WITH_RSA
public static final String SHA512_WITH_RSA = "SHA512withRSA"SHA512withRSA – RSA PKCS#1 v1.5 with SHA-512.SHA256_WITH_ECDSA
public static final String SHA256_WITH_ECDSA = "SHA256withECDSA"SHA256withECDSA – ECDSA with SHA-256 (P-256 curve).SHA384_WITH_ECDSA
public static final String SHA384_WITH_ECDSA = "SHA384withECDSA"SHA384withECDSA – ECDSA with SHA-384 (P-384 curve).SHA512_WITH_ECDSA
public static final String SHA512_WITH_ECDSA = "SHA512withECDSA"SHA512withECDSA – ECDSA with SHA-512 (P-521 curve).Method details
sign
public static byte[] sign(String algorithm, PrivateKey key, byte[] data)Signs
data with the given algorithm and private key.verify
public static boolean verify(String algorithm, PublicKey key, byte[] data, byte[] signature)Verifies
signature against data using the given algorithm and
public key.