Java Code Examples for com.jeesuite.common.crypt.Base64#decode()

The following examples show how to use com.jeesuite.common.crypt.Base64#decode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RsaSignUtils.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public static PublicKey loadPublicKey(String pubKeyString) {
	byte[] keyBytes = Base64.decode(pubKeyString);
	X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(keyBytes);
	try {
		KeyFactory factory = KeyFactory.getInstance(KEY_ALGORITHM);
		PublicKey publicKey = factory.generatePublic(x509EncodedKeySpec);
		return publicKey;
	} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {}
	return null;
}
 
Example 2
Source File: RsaSignUtils.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public static PrivateKey loadPrivateKey(String privateKeyString) {
	try {
		byte[] privateKeyBytes = Base64.decode(privateKeyString);
		PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
		KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
		return keyFactory.generatePrivate(pkcs8KeySpec);
	} catch (Exception e) {
		// TODO: handle exception
	}
	return null;
}
 
Example 3
Source File: RsaSignUtils.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public static boolean verifySignature(String contents, String sign, PublicKey publicKey) {
	try {
		byte[] data = contents.getBytes(StandardCharsets.UTF_8.name());
		byte[] dataSignature = Base64.decode(sign);

		Signature signature = Signature.getInstance(SIGN_ALGORITHM);
		signature.initVerify(publicKey);
		signature.update(data, 0, data.length);
		return signature.verify(dataSignature);
	} catch (Exception e) {
		return false;
	}

}
 
Example 4
Source File: SecurityCryptUtils.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
public static String decrypt(String data) {
	 byte[] bytes = Base64.decode(data);
	 data = new String(bytes, StandardCharsets.UTF_8);
	 return DES.decrypt(cryptKey, data);
}
 
Example 5
Source File: SimpleCryptUtils.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public static String decrypt(String key,String data) {
 key = DigestUtils.md5Short(key) + KEY_TAIL;
 byte[] bytes = Base64.decode(data);
 data = new String(bytes, StandardCharsets.UTF_8);
 return DES.decrypt(key, data);
}
 
Example 6
Source File: RsaSignUtils.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public static String decrypt(PrivateKey key, String encodedText) {
	byte[] bytes = Base64.decode(encodedText);
	return decrypt(key, bytes);
}
 
Example 7
Source File: SecurityCryptUtils.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public static String decrypt(String data) {
	 byte[] bytes = Base64.decode(data);
	 data = new String(bytes, StandardCharsets.UTF_8);
	 return DES.decrypt(cryptKey, data);
}