Code example for GeneralSecurityException

0
    public static SecretKey generateSecretKey(PrivateKey privateKey, PublicKey publicKey) throws NoSuchAlgorithmException, GeneralSecurityException {
        if(privateKey == null)
        	throw new GeneralSecurityException("Missing private key");
         
        if(publicKey == null)
        	throw new GeneralSecurityException("Missing public key");
    	 
    	KeyAgreement ka = KeyAgreement.getInstance(KEY_EXCHANGE_PROTOCOL);
        ka.init(privateKey);
        ka.doPhase(publicKey, true);
                 
        SecretKey secretKey = ka.generateSecret(ENCRYPTION_ALGORITHM);        
         
        return secretKey; 
    } 
     
     
    /** 
     * Get a list of the currently stored public keys, excluding your own. Hashmap with number and description 
     *  
     * @param context