Java 8 RSAPublicKey - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 RSAPublicKey class.

This code example shows how to use the following methods:getModulus, getPublicExponent
This code example shows how to use the following methods:getModulus, getPublicExponent
This code example shows how to use the following methods:getModulus, getPublicExponent
	public void testRecoverKeyPair_Rsa() throws Exception { 
		KeyPair kp = PubkeyUtils.recoverKeyPair(RSA_KEY_PKCS8);
 
		RSAPublicKey pubKey = (RSAPublicKey) kp.getPublic();
 
		assertEquals(RSA_KEY_N, pubKey.getModulus());
		assertEquals(RSA_KEY_E, pubKey.getPublicExponent());
	} 
 
	public void testRecoverKeyPair_Ec() throws Exception { 
		KeyPair kp = PubkeyUtils.recoverKeyPair(EC_KEY_PKCS8);
 
		ECPublicKey pubKey = (ECPublicKey) kp.getPublic();
 
		assertEquals(EC_KEY_pub_x, pubKey.getW().getAffineX());
		assertEquals(EC_KEY_pub_y, pubKey.getW().getAffineY());
	} 
 
	private static class MyPrivateKey implements PrivateKey {
		public String getAlgorithm() {
7
CodeRank
This code example shows how to use the following methods:getEncoded
	} 
 
	@Override 
	public void serialize(final Type type, final Object object, final DataOutputStream dos) throws IOException {
		final RSAPublicKey key = (RSAPublicKey) object;
		final byte[] encoded = key.getEncoded();
		dos.writeInt(encoded.length);
		dos.write(encoded);
	} 
 
 
} 
6
CodeRank
This code example shows how to use the following methods:getModulus, getPublicExponent
      builder.put("private", pem(RSAPrivateKey.class.cast(pair.getPrivate())));
      return builder.build();
   } 
 
   public static String encodeAsOpenSSH(RSAPublicKey key) {
      byte[] keyBlob = keyBlob(key.getPublicExponent(), key.getModulus());
      return "ssh-rsa " + base64().encode(keyBlob);
   } 
 
   /** 
    * @param privateKeyPEM 
    *           RSA private key in PEM format 
    * @param publicKeyOpenSSH 
    *           RSA public key in OpenSSH format 
    * @return true if the keypairs match 
    */ 
   public static boolean privateKeyMatchesPublicKey(String privateKeyPEM, String publicKeyOpenSSH) {
      KeySpec privateKeySpec = privateKeySpec(privateKeyPEM);
      checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec,
               "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec);
6
CodeRank
This code example shows how to use the following methods:getModulus, getPublicExponent
    } 
 
    static RSAKeyParameters generatePublicKeyParameter( 
        RSAPublicKey key)
    { 
        return new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent());
 
    } 
 
    static RSAKeyParameters generatePrivateKeyParameter( 
        RSAPrivateKey key)
    { 
        if (key instanceof RSAPrivateCrtKey)
        { 
            RSAPrivateCrtKey k = (RSAPrivateCrtKey)key;
 
            return new RSAPrivateCrtKeyParameters(k.getModulus(),
                k.getPublicExponent(), k.getPrivateExponent(),
                k.getPrimeP(), k.getPrimeQ(), k.getPrimeExponentP(), k.getPrimeExponentQ(), k.getCrtCoefficient());
        } 
6
CodeRank
This code example shows how to use the following methods:getModulus, getPublicExponent
public class RSAUtil 
{ 
    static public RSAKeyParameters generatePublicKeyParameter( 
        RSAPublicKey    key)
    { 
        return new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent());
 
    } 
 
    static public RSAKeyParameters generatePrivateKeyParameter( 
        RSAPrivateKey    key)
    { 
        if (key instanceof RSAPrivateCrtKey)
        { 
            RSAPrivateCrtKey    k = (RSAPrivateCrtKey)key;
 
            return new RSAPrivateCrtKeyParameters(k.getModulus(),
                k.getPublicExponent(), k.getPrivateExponent(),
                k.getPrimeP(), k.getPrimeQ(), k.getPrimeExponentP(),                            k.getPrimeExponentQ(), k.getCrtCoefficient());
        } 
6
CodeRank
This code example shows how to use the following methods:getModulus, getPublicExponent
    /** 
     * @param key to perform sanity checks on 
     * @throws Exception if the key has the wrong size or public exponent 
     */ 
    static void check(RSAPublicKey key) throws Exception {
        BigInteger pubexp = key.getPublicExponent();
        BigInteger modulus = key.getModulus();
 
        if (!pubexp.equals(BigInteger.valueOf(3)))
                throw new Exception("Public exponent should be 3 but is " +
                        pubexp.toString(10) + ".");
 
        if (modulus.bitLength() != 2048)
             throw new Exception("Modulus should be 2048 bits long but is " +
                        modulus.bitLength() + " bits.");
    } 
 
    /** 
     * @param key to output 
     * @return a C initializer representing this public key. 
6
CodeRank
This code example shows how to use the following methods:getModulus, getPublicExponent
		RSAPublicKey rsaKey = (RSAPublicKey) pubKey;
		BigInteger sigInt = new BigInteger(1, signature);
		BigInteger sigSigInt = new BigInteger(signature);
		System.out.println("Signature length " + signature.length + " sign? " + sigSigInt.signum());
 
		BigInteger paddedMessage = sigInt.modPow(rsaKey.getPublicExponent(), rsaKey.getModulus());
		System.out.println("\nSignature: " + DataUtils.printHexBytes(signature) + "\n");
		System.out.println("Inverted signature: " + DataUtils.printHexBytes(paddedMessage.toByteArray()) + "\n");
	 
		if (sigSigInt.signum() < 0) {
			BigInteger paddedSignedMessage = sigSigInt.modPow(rsaKey.getPublicExponent(), rsaKey.getModulus());
			System.out.println("Inverted signed signature: " + DataUtils.printHexBytes(paddedSignedMessage.toByteArray()) + "\n");
		 
		} 
	} 
 
	public static ContentObject readObjectFile(String filePath) 
	throws ContentDecodingException, FileNotFoundException {
		FileInputStream fis = new FileInputStream(filePath);
		BufferedInputStream bis = new BufferedInputStream(fis);
6
CodeRank
This code example shows how to use the following methods:getModulus, getPublicExponent
    } 
     
    static RSAKeyParameters generatePublicKeyParameter( 
        RSAPublicKey    key)
    { 
        return new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent());
 
    } 
 
    static RSAKeyParameters generatePrivateKeyParameter( 
        RSAPrivateKey    key)
    { 
        if (key instanceof RSAPrivateCrtKey)
        { 
            RSAPrivateCrtKey    k = (RSAPrivateCrtKey)key;
 
            return new RSAPrivateCrtKeyParameters(k.getModulus(),
                k.getPublicExponent(), k.getPrivateExponent(),
                k.getPrimeP(), k.getPrimeQ(), k.getPrimeExponentP(),                            k.getPrimeExponentQ(), k.getCrtCoefficient());
        } 
6
CodeRank

Related Java 8 RSAPublicKey Questions & Answers:

See Code Examples for Java 8 RSAPublicKey Methods: