Package java.security.interfaces

Examples of java.security.interfaces.RSAPrivateKey


    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
    KeyPair keyPair = keyGen.genKeyPair();
    RSAPublicKey rsaPublicKeyIn = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateKey rsaPrivateKeyIn = (RSAPrivateKey)keyPair.getPrivate();

    RSAKey rsaJWK = new RSAKey.Builder(rsaPublicKeyIn).privateKey(rsaPrivateKeyIn).build();

    // Compare JWK values with original Java RSA values
    assertEquals(rsaPublicKeyIn.getPublicExponent(), rsaJWK.getPublicExponent().decodeToBigInteger());
    assertEquals(rsaPublicKeyIn.getModulus(), rsaJWK.getModulus().decodeToBigInteger());
    assertEquals(rsaPrivateKeyIn.getPrivateExponent(), rsaJWK.getPrivateExponent().decodeToBigInteger());

    // Convert back to Java RSA keys
    RSAPublicKey rsaPublicKeyOut = rsaJWK.toRSAPublicKey();
    RSAPrivateKey rsaPrivateKeyOut = rsaJWK.toRSAPrivateKey();

    assertEquals(rsaPublicKeyIn.getAlgorithm(), rsaPublicKeyOut.getAlgorithm());
    assertEquals(rsaPublicKeyIn.getPublicExponent(), rsaPublicKeyOut.getPublicExponent());
    assertEquals(rsaPublicKeyIn.getModulus(), rsaPublicKeyOut.getModulus());

    assertEquals(rsaPrivateKeyIn.getAlgorithm(), rsaPrivateKeyOut.getAlgorithm());
    assertEquals(rsaPrivateKeyIn.getPrivateExponent(), rsaPrivateKeyOut.getPrivateExponent());

    // Compare encoded forms
    assertEquals("Public RSA", Base64.encode(rsaPublicKeyIn.getEncoded()).toString(), Base64.encode(rsaPublicKeyOut.getEncoded()).toString());
    assertEquals("Private RSA", Base64.encode(rsaPrivateKeyIn.getEncoded()).toString(), Base64.encode(rsaPrivateKeyOut.getEncoded()).toString());

    RSAKey rsaJWK2 = new RSAKey.Builder(rsaPublicKeyOut).privateKey(rsaPrivateKeyOut).build();

    // Compare JWK values with original Java RSA values
    assertEquals(rsaPublicKeyIn.getPublicExponent(), rsaJWK2.getPublicExponent().decodeToBigInteger());
View Full Code Here


      "jJ-GtiseaDVWt7dcH0cfwxgFUHpQh7FoCrjFJ6h6ZEpMF6xmujs4qMpP" +
      "z8aaI4", jwk.getFirstCRTCoefficient().toString());

    // Convert to Java RSA key object
    RSAPublicKey rsaPublicKey = jwk.toRSAPublicKey();
    RSAPrivateKey rsaPrivateKey = jwk.toRSAPrivateKey();

    jwk = new RSAKey.Builder(rsaPublicKey).privateKey(rsaPrivateKey).build();

    assertEquals("n4EPtAOCc9AlkeQHPzHStgAbgs7bTZLwUBZdR8_KuKPEHLd4rHVTeT" +
      "-O-XV2jRojdNhxJWTDvNd7nqQ0VEiZQHz_AJmSCpMaJMRBSFKrKb2wqV" +
View Full Code Here

      "Gl7CF1DZkBJMTQN6EshYzZfxW08mIO8M6Rzuh0beL6fG9mkDcIyPrBXx"+
      "2bQ_mM", jwk.getFirstCRTCoefficient().toString());

    // Convert to Java RSA key object
    RSAPublicKey rsaPublicKey = jwk.toRSAPublicKey();
    RSAPrivateKey rsaPrivateKey = jwk.toRSAPrivateKey();

    jwk = new RSAKey.Builder(rsaPublicKey).privateKey(rsaPrivateKey).build();

    assertEquals("maxhbsmBtdQ3CNrKvprUE6n9lYcregDMLYNeTAWcLj8NnPU9XIYegT"+
      "HVHQjxKDSHP2l-F5jS7sppG1wgdAqZyhnWvXhYNvcM7RfgKxqNx_xAHx"+
View Full Code Here

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(2048);

    KeyPair kp = kpg.genKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey)kp.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey)kp.getPrivate();

    // Need BouncyCastle for PSS
    Security.addProvider(BouncyCastleProviderSingleton.getInstance());

    RSASSASigner signer = new RSASSASigner(privateKey);
View Full Code Here

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(2048);

    KeyPair kp = kpg.genKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey)kp.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey)kp.getPrivate();

    // Need BouncyCastle for PSS
    Security.addProvider(BouncyCastleProviderSingleton.getInstance());

    RSASSASigner signer = new RSASSASigner(privateKey);
View Full Code Here

    KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
    keyGenerator.initialize(1024);

    KeyPair kp = keyGenerator.genKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey)kp.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey)kp.getPrivate();

    // Create RSA-signer with the private key
    JWSSigner signer = new RSASSASigner(privateKey);

    // Prepare JWS object with simple string as payload
View Full Code Here

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
    KeyPair keyPair = keyGen.genKeyPair();
    RSAPublicKey rsaPublicKey = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateKey rsaPrivateKey = (RSAPrivateKey)keyPair.getPrivate();

    // Create signer from raw Java RSA key
    JWSObject jwsObject1 = new JWSObject(new JWSHeader(JWSAlgorithm.RS256), new Payload("test123"));
    JWSSigner signer = new RSASSASigner(rsaPrivateKey);
    jwsObject1.sign(signer);
View Full Code Here

TOP

Related Classes of java.security.interfaces.RSAPrivateKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.