Java 8 InvalidKeySpecException - 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 InvalidKeySpecException class.

This code example shows how to use the following methods:
                return new OpenSSLRSAPublicKey(key);
            } catch (Exception e) {
                throw new InvalidKeySpecException(e);
            } 
        } 
        throw new InvalidKeySpecException("Must use RSAPublicKeySpec or X509EncodedKeySpec; was "
                + keySpec.getClass().getName());
    } 
 
    @Override 
    protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
        if (keySpec instanceof RSAPrivateCrtKeySpec) {
            RSAPrivateCrtKeySpec rsaKeySpec = (RSAPrivateCrtKeySpec) keySpec;
 
            return new OpenSSLRSAPrivateCrtKey(rsaKeySpec);
        } else if (keySpec instanceof RSAPrivateKeySpec) {
            RSAPrivateKeySpec rsaKeySpec = (RSAPrivateKeySpec) keySpec;
 
            return new OpenSSLRSAPrivateKey(rsaKeySpec);
        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
6
CodeRank
This code example shows how to use the following methods:
                    primeQ == null ? null : primeQ.toByteArray(),
                    primeExponentP == null ? null : primeExponentP.toByteArray(),
                    primeExponentQ == null ? null : primeExponentQ.toByteArray(),
                    crtCoefficient == null ? null : crtCoefficient.toByteArray()));
        } catch (Exception e) {
            throw new InvalidKeySpecException(e);
        } 
    } 
 
    static OpenSSLKey getInstance(RSAPrivateCrtKey rsaPrivateKey) throws InvalidKeyException {
        BigInteger modulus = rsaPrivateKey.getModulus();
        BigInteger privateExponent = rsaPrivateKey.getPrivateExponent();
 
        if (modulus == null) {
            throw new InvalidKeyException("modulus == null");
        } else if (privateExponent == null) {
            throw new InvalidKeyException("privateExponent == null");
        } 
 
        try { 
6
CodeRank
This code example shows how to use the following methods:getCause, getMessage
     * Test for <code>InvalidKeySpecException(Throwable)</code> constructor 
     * Assertion: constructs InvalidKeySpecException when <code>cause</code> 
     * is not null 
     */ 
    public void testInvalidKeySpecException05() { 
        InvalidKeySpecException tE = new InvalidKeySpecException(tCause);
        if (tE.getMessage() != null) {
            String toS = tCause.toString();
            String getM = tE.getMessage();
            assertTrue("getMessage() should contain ".concat(toS), (getM
                    .indexOf(toS) != -1));
        } 
        assertNotNull("getCause() must not return null", tE.getCause());
        assertEquals("getCause() must return ".concat(tCause.toString()), tE
                .getCause(), tCause);
    } 
 
    /** 
     * Test for <code>InvalidKeySpecException(String, Throwable)</code> 
     * constructor Assertion: constructs InvalidKeySpecException when 
6
CodeRank
This code example shows how to use the following methods:getCause, getMessage
     * Assertion: constructs InvalidKeySpecException when <code>msg</code> is 
     * null 
     */ 
    public void testInvalidKeySpecException03() { 
        String msg = null;
        InvalidKeySpecException tE = new InvalidKeySpecException(msg);
        assertNull("getMessage() must return null.", tE.getMessage());
        assertNull("getCause() must return null", tE.getCause());
    } 
 
    /** 
     * Test for <code>InvalidKeySpecException(Throwable)</code> constructor 
     * Assertion: constructs InvalidKeySpecException when <code>cause</code> 
     * is null 
     */ 
    public void testInvalidKeySpecException04() { 
        Throwable cause = null;
        InvalidKeySpecException tE = new InvalidKeySpecException(cause);
        assertNull("getMessage() must return null.", tE.getMessage());
        assertNull("getCause() must return null", tE.getCause());
6
CodeRank
This code example shows how to use the following methods:getMessage
			keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);			
			key = keyFactory.generatePrivate(pkcs8KeySpec);
		} catch (NoSuchAlgorithmException e) {
			Logger.error(e.getMessage(), e);
		} catch (InvalidKeySpecException e) {
			Logger.error(e.getMessage(), e);
		} 
		 
		return key;
	} 
	 
	public static PublicKey toPublicKey(byte[] keyBytes) {
		PublicKey key = null;
		if (keyBytes == null) {
			return key;
		} 
		 
		byte[] decodedKeyBytes = Base64.decodeBase64(keyBytes);
		X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(
				decodedKeyBytes);
5
CodeRank
This code example shows how to use the following methods:
        else if (spec.isAssignableFrom(X509EncodedKeySpec.class) && key.getFormat().equals("X.509"))
        { 
            return new X509EncodedKeySpec(key.getEncoded());
        } 
 
        throw new InvalidKeySpecException("not implemented yet " + key + " " + spec);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getClass, getMessage
	CertificateEncodingException, InvalidKeySpecException, NoSuchAlgorithmException {
		ContentObject keyObject = readObjectFile(filePath);
		try { 
			return CryptoUtil.getPublicKey(keyObject.content());
		} catch (InvalidKeySpecException e) {
			System.out.println("Exception decoding public key! " + filePath + " " + e.getClass().getName() + ": " + e.getMessage());
			FileOutputStream fos = new FileOutputStream("contentDump.der");
			fos.write(keyObject.content());
			fos.close();
			throw e;
		} 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:
 
            return (KeySpec)c.newInstance(p);
        } 
        catch (Exception e)
        { 
            throw new InvalidKeySpecException(e.toString());
        } 
    } 
 
    protected SecretKey engineTranslateKey(
        SecretKey key)
    throws InvalidKeyException 
    { 
        if (key == null)
        { 
            throw new InvalidKeyException("key parameter is null");
        } 
         
        if (!key.getAlgorithm().equalsIgnoreCase(algName))
        { 
5
CodeRank
This code example shows how to use the following methods:
        else if (keySpec.isAssignableFrom(X509EncodedKeySpec.class) && key.getFormat().equals("X.509"))
        { 
            return new X509EncodedKeySpec(key.getEncoded());
        } 
 
        throw new InvalidKeySpecException("not implemented yet " + key + " " + keySpec);
    } 
 
    protected Key engineTranslateKey(Key key)
        throws InvalidKeyException 
    { 
        throw new InvalidKeyException("not implemented yet " + key);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getClass, getMessage
		} catch (CertificateEncodingException e) {
			Log.severe("Cannot decode public key " + e.getClass().getName() + ": " + e.getMessage());
			Log.severe("Blockname : " + ((CCNInputStream)input).currentSegmentName());
			throw new IOException("Cannot decode public key " + e.getClass().getName() + ": " + e.getMessage());
		} catch (InvalidKeySpecException e) {
			Log.warning("Cannot decode public key from block: " + ((CCNInputStream)input).currentSegmentName() + "  " + e.getClass().getName() + ": " + e.getMessage());
			throw new IOException("Cannot decode public key " + e.getClass().getName() + ": " + e.getMessage());
		} 
	} 
 
	@Override 
	protected void writeObjectImpl(OutputStream output) throws ContentEncodingException, IOException {
		if (null == data()) 
			throw new ContentNotReadyException("No content available to save for object " + getBaseName()); 
		byte [] encoded = data().getEncoded();
		output.write(encoded);
	} 
	 
	/** 
	 * Many cryptographic providers don't implement equals() correctly. 
5
CodeRank

Related Java 8 InvalidKeySpecException Questions & Answers:

See Code Examples for Java 8 InvalidKeySpecException Methods: