还原私钥，PKCS8EncodedKeySpec 用于构建私钥的规范

@param keyBytes
@return
197513
private static PrivateKey loadPrivateKey(byte[] keyBytes) {
        PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(
                keyBytes);
        try {
            KeyFactory factory = KeyFactory.getInstance(KEY_ALGORITHM);
            PrivateKey privateKey = factory
                    .generatePrivate(pkcs8EncodedKeySpec);
            return privateKey;
        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
721777
byte getKeyByte(int keyId, int byteId)
    {
        if (byteId >= _keys[keyId].length)
        {
            return 0;
        }
        return _keys[keyId][byteId];
    }
890538
protected byte[] keyToBytes(String key) throws Exception {
		int i = key.indexOf(':');

		byte[] part1;
		byte[] part2;
		boolean compressed;

		if (i == -1) {
			part1 = key.getBytes(StandardCharsets.UTF_8);
			part2 = new byte[0];
			compressed = false;
		} else {
			part1 = key.substring(0, i).getBytes(StandardCharsets.UTF_8);
			part2 = key.substring(i + 1).getBytes(StandardCharsets.UTF_8);
			if (compressAbove > 0 && part2.length > compressAbove) {
				part2 = compress(part2, compressionLevel);
				compressed = true;
			} else {
				compressed = false;
			}
		}

		// Write key packet
		ByteArrayOutputStream out = new ByteArrayOutputStream(part1.length + part2.length + 16);
		DataOutputStream dos = new DataOutputStream(out);
		dos.writeInt(part1.length);
		dos.write(part1);
		dos.writeInt(part2.length);
		dos.write(part2);
		dos.writeBoolean(compressed);
		dos.flush();

		// Return key as partly compressed bytes
		return out.toByteArray();
	}
429823
public byte[] decrypt(String data, KeyType keyType) {
		return decrypt(SecureUtil.decode(data), keyType);
	}
1312884
public static UTF8String fromBytes(byte[] bytes, int offset, int numBytes) {
    if (bytes != null) {
      return new UTF8String(bytes, BYTE_ARRAY_OFFSET + offset, numBytes);
    } else {
      return null;
    }
  }
29578
public PublicKey getPublicKey_X509Encoded(byte[] keyBytes){  
       try {
           X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);  
           KeyFactory keyFactory = KeyFactory.getInstance(algorithm);  
           return keyFactory.generatePublic(spec);  
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
       return null;
    }
120988
private String decryptInternal(SecretKeySpec key, byte[] encryptedBytes) {
        try {
            Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
            return new String(decryptedBytes, ENCODING);
        } catch (GeneralSecurityException e) {
            throw new RuntimeException("Exception during decryptInternal: " + e, e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Exception during encryptInternal: " + e, e);
        }
    }
648273
public String encryptBcd(String data, KeyType keyType, Charset charset) {
		return BCD.bcdToStr(encrypt(data, charset, keyType));
	}
469602
public static String sign(byte[] data, String privateKey) throws Exception {
        String keyBytes = Base64Utils.decode(privateKey);
        PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes.getBytes());
        KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
        PrivateKey privateK = keyFactory.generatePrivate(pkcs8KeySpec);
        Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
        signature.initSign(privateK);
        signature.update(data);
        return String.valueOf(Base64Utils.encode(signature.sign()));
    }
582147
public byte[] decrypt(InputStream data, KeyType keyType) throws IORuntimeException {
		return decrypt(IoUtil.readBytes(data), keyType);
	}
1199658
public static byte[] keyGenPrivate(byte[] randomBytes) {

        if (randomBytes.length < 32) {
            throw new RuntimeException("Random bytes too small");
        }

        // Hashing Random Bytes instead of using random bytes directly
        // Just in case as reference ed255519 implementation do same
        byte[] privateKey = new byte[32];
        Digest sha256 = Crypto.createSHA256();
        sha256.update(randomBytes, 0, randomBytes.length);
        sha256.doFinal(privateKey, 0);

        // Performing bit's flipping
        privateKey[0] &= 248;
        privateKey[31] &= 127;
        privateKey[31] |= 64;

        return privateKey;
    }
518317
@Nullable
  @ReturnsMutableCopy
  public static byte [] safeDecode (@Nullable final byte [] aEncodedBytes, final int nOptions)
  {
    if (aEncodedBytes != null)
      return safeDecode (aEncodedBytes, 0, aEncodedBytes.length, nOptions);
    return null;
  }
16381
private static byte[] applyCipher(byte[] keyBytes, byte[] textBytes) {
        byte[] result = new byte[textBytes.length];
        for (int i = 0; i < result.length; i++) {
            int keyPos = i % keyBytes.length;
            result[i] = (byte) (textBytes[i] ^ keyBytes[keyPos]);
        }
        return result;
    }
146906
private static PublicKey commonGetPublickeyByText(String keyText)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        byte[] keyBytes = Base64.base64ToByteArray(keyText);
        X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance(RSA);
        return keyFactory.generatePublic(x509KeySpec);
    }
1329286
public byte[] decryptFromBcd(String data, KeyType keyType, Charset charset) {
		final byte[] dataBytes = BCD.ascToBcd(StrUtil.bytes(data, charset));
		return decrypt(dataBytes, keyType);
	}
786864
private byte[] encodePKCS7() throws CertificateEncodingException {
        PKCS7 p7 = new PKCS7(new AlgorithmId[0],
                             new ContentInfo(ContentInfo.DATA_OID, null),
                             certs.toArray(new X509Certificate[certs.size()]),
                             new SignerInfo[0]);
        DerOutputStream derout = new DerOutputStream();
        try {
            p7.encodeSignedData(derout);
        } catch (IOException ioe) {
            throw new CertificateEncodingException(ioe.getMessage());
        }
        return derout.toByteArray();
    }
355628
public byte[] encrypt(InputStream data, KeyType keyType) throws IORuntimeException {
		return encrypt(IoUtil.readBytes(data), keyType);
	}