Java Key Public getPublicKeyFromBytes(final String algorithm, final byte[] publicKeyBytes)

Here you can find the source of getPublicKeyFromBytes(final String algorithm, final byte[] publicKeyBytes)

Description

get Public Key From Bytes

License

Open Source License

Declaration

private static PublicKey getPublicKeyFromBytes(final String algorithm, final byte[] publicKeyBytes) 

Method Source Code

//package com.java2s;
/**/*w w  w.  j a va2s . com*/
 * Copyright (C) 2010-2016 Structr GmbH
 *
 * This file is part of Structr <http://structr.org>.
 *
 * Structr is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Structr is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Structr.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.security.KeyFactory;

import java.security.PublicKey;

import java.security.spec.X509EncodedKeySpec;

public class Main {
    private static PublicKey getPublicKeyFromBytes(final String algorithm, final byte[] publicKeyBytes) {

        try {

            final KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
            final X509EncodedKeySpec spec = new X509EncodedKeySpec(publicKeyBytes);

            return keyFactory.generatePublic(spec);

        } catch (Throwable t) {
            t.printStackTrace();
        }

        return null;
    }
}

Related

  1. getPublicKey(String key)
  2. getPublicKey(String modulus, String exponent)
  3. getPublicKey(String publicKeyContents)
  4. getPublicKey(String publicKeyFile)
  5. getPublicKey(String publicKeyFilepath, String algorithm)
  6. getPublicKeyFromFile(File cert, String alias, String password)
  7. getPublicKeyFromPEMFile(String fileName, String jceProvider)
  8. getPublicKeyFromString(String certificateString)
  9. getPublicKeyModulus(RSAPublicKey publicKey)