Code example for PrivateKey

Methods: getEncoded

0
    /* Functions for encoding and decoding public and private keys */ 
    private static String encodeKey(PublicKey thePK) {
        return theCryptographyPrefix + encodeBytes(thePK.getEncoded());
    } 
    private static String encodeKey(PrivateKey theSK) {
        return theCryptographyPrefix + encodeBytes(theSK.getEncoded());
    } 
    private static String encodeSignature(byte[] theSignatureBytes) {
        return theCryptographyPrefix + encodeBytes(theSignatureBytes);
    } 
    private static PublicKey decodePublicKey(String thePK) {
        if (!thePK.startsWith(theCryptographyPrefix)) return null;
        thePK = thePK.replaceFirst(theCryptographyPrefix, "");
         
        try { 
            KeyFactory kf = KeyFactory.getInstance("RSA");
            return kf.generatePublic(new X509EncodedKeySpec(decodeBytes(thePK)));
        } catch (NoSuchAlgorithmException e) {
            return null; 
        } catch (InvalidKeySpecException e) {
            return null;