use of io.jans.as.model.crypto.signature.RSAKeyFactory in project jans by JanssenProject.
the class SignatureTest method generateRS384Keys.
@Test
public void generateRS384Keys() throws Exception {
showTitle("TEST: generateRS384Keys");
KeyFactory<RSAPrivateKey, RSAPublicKey> keyFactory = new RSAKeyFactory(SignatureAlgorithm.RS384, "CN=Test CA Certificate");
Key<RSAPrivateKey, RSAPublicKey> key = keyFactory.getKey();
RSAPrivateKey privateKey = key.getPrivateKey();
RSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
RSASigner rsaSigner1 = new RSASigner(SignatureAlgorithm.RS384, privateKey);
String signature = rsaSigner1.generateSignature(signingInput);
RSASigner rsaSigner2 = new RSASigner(SignatureAlgorithm.RS384, publicKey);
assertTrue(rsaSigner2.validateSignature(signingInput, signature));
RSASigner rsaSigner3 = new RSASigner(SignatureAlgorithm.RS384, certificate);
assertTrue(rsaSigner3.validateSignature(signingInput, signature));
}
use of io.jans.as.model.crypto.signature.RSAKeyFactory in project jans by JanssenProject.
the class SignatureTest method generateRS256Keys.
@Test
public void generateRS256Keys() throws Exception {
showTitle("TEST: generateRS256Keys");
KeyFactory<RSAPrivateKey, RSAPublicKey> keyFactory = new RSAKeyFactory(SignatureAlgorithm.RS256, "CN=Test CA Certificate");
Key<RSAPrivateKey, RSAPublicKey> key = keyFactory.getKey();
RSAPrivateKey privateKey = key.getPrivateKey();
RSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
RSASigner rsaSigner1 = new RSASigner(SignatureAlgorithm.RS256, privateKey);
String signature = rsaSigner1.generateSignature(signingInput);
RSASigner rsaSigner2 = new RSASigner(SignatureAlgorithm.RS256, publicKey);
assertTrue(rsaSigner2.validateSignature(signingInput, signature));
RSASigner rsaSigner3 = new RSASigner(SignatureAlgorithm.RS256, certificate);
assertTrue(rsaSigner3.validateSignature(signingInput, signature));
}
use of io.jans.as.model.crypto.signature.RSAKeyFactory in project jans by JanssenProject.
the class SignatureTest method generateRS512Keys.
@Test
public void generateRS512Keys() throws Exception {
showTitle("TEST: generateRS512Keys");
KeyFactory<RSAPrivateKey, RSAPublicKey> keyFactory = new RSAKeyFactory(SignatureAlgorithm.RS512, "CN=Test CA Certificate");
Key<RSAPrivateKey, RSAPublicKey> key = keyFactory.getKey();
RSAPrivateKey privateKey = key.getPrivateKey();
RSAPublicKey publicKey = key.getPublicKey();
Certificate certificate = key.getCertificate();
System.out.println(key);
String signingInput = "Hello World!";
RSASigner rsaSigner1 = new RSASigner(SignatureAlgorithm.RS512, privateKey);
String signature = rsaSigner1.generateSignature(signingInput);
RSASigner rsaSigner2 = new RSASigner(SignatureAlgorithm.RS512, publicKey);
assertTrue(rsaSigner2.validateSignature(signingInput, signature));
RSASigner rsaSigner3 = new RSASigner(SignatureAlgorithm.RS512, certificate);
assertTrue(rsaSigner3.validateSignature(signingInput, signature));
}
Aggregations