use of org.apache.commons.codec.binary.Base64.encodeBase64String in project coprhd-controller by CoprHD.
the class RESTClient method setResourceHeaders.
/**
* Sets required headers into the passed WebResource.
*
* @param resource The resource to which headers are added.
*/
Builder setResourceHeaders(WebResource resource) {
StringBuffer credentials = new StringBuffer(_username).append(HDSConstants.COLON).append(_password);
Base64 base64 = new Base64();
String encodedStr = base64.encodeToString(credentials.toString().getBytes());
return resource.header("Authorization", "Basic " + encodedStr);
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project pancm_project by xuwujing.
the class AESEncryptDecrypt method decode.
/**
* 解密需要解密的密文
*
* @param code 密文
* @param key the key
* @return the string
* @key 密钥
*/
public static String decode(String code, String key) {
if (null == code || null == key) {
return null;
}
String plainText = null;
try {
// BASE64 DECODE
// BASE64Decoder b64 = new BASE64Decoder();
// byte[] inputStream = b64.decodeBuffer(code);
// BASE64 DECODE
byte[] inputStream = new Base64().decode(code);
// DESj解密
byte[] key_ = getKey(key);
SecretKey desKey = getDesKey(key_);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, desKey);
byte[] desText = cipher.doFinal(inputStream);
plainText = new String(desText, "UTF-8");
// 因为MD5是固定的32byte的长度,这里截取32byte之后的内容即为明文内容
plainText = plainText.substring(32, plainText.length());
} catch (Exception e) {
e.printStackTrace();
return null;
}
return plainText;
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project pancm_project by xuwujing.
the class SecretKeyhepler method getPublicKey.
// 获取公钥
public static PublicKey getPublicKey(String key) throws Exception {
byte[] keyBytes;
Base64 base64 = new Base64();
keyBytes = base64.decode(key);
/* keyBytes = (new BASE64Decoder()).decodeBuffer(key);*/
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
PublicKey publicKey = keyFactory.generatePublic(keySpec);
return publicKey;
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project pancm_project by xuwujing.
the class SecretKeyhepler method getPrivateKey.
// 获取私钥
public static PrivateKey getPrivateKey(String key) throws Exception {
byte[] keyBytes;
/*keyBytes = (new BASE64Decoder()).decodeBuffer(key);*/
Base64 base64 = new Base64();
keyBytes = base64.decode(key);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
return privateKey;
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project coprhd-controller by CoprHD.
the class KeyCertificatePairGenerator method getCertificateChainAsString.
/**
* @param certChain - the certificate chain to parse to PEM format
* @return the specified certificate chain in PEM format
* @throws IOException
* @throws CertificateEncodingException
*/
public static String getCertificateChainAsString(Certificate[] certChain) throws CertificateEncodingException {
StringBuilder builder = new StringBuilder();
Base64 encoder = new Base64(PEM_OUTPUT_LINE_SIZE);
boolean isFirst = true;
for (Certificate certificate : certChain) {
if (!isFirst) {
builder.append(System.lineSeparator());
}
builder.append(PEM_BEGIN_CERT);
builder.append(System.lineSeparator());
builder.append(encoder.encodeAsString(certificate.getEncoded()));
builder.append(PEM_END_CERT);
isFirst = false;
}
return builder.toString();
}
Aggregations