Code example for Key

Methods: getAlgorithm

     * Key object's getAlgorithm method. 
     * @param key The key that will be used to perform the encryption. 
    Encryption createEncryption(Key key) throws NoSuchAlgorithmException{
        String algorithm = key.getAlgorithm();
        if ("DES".equals(algorithm))
          return new DESEncryption(key);
        if ("RSA".equals(algorithm))
          return new RSAEncryption(key);
        throw new NoSuchAlgorithmException(algorithm);
    } // createEncryption(Key) 
} // class EncryptionFactory 
Experience pair programming with AI  Get Codota for Java