因为比较简单,只做记录:
/**
* HmacSHA1 Encrypt.
* @param encryptText : content to be encrypted.
* @param encryptKey : secret key.
* @return Encrypted bytes.
**/
public static byte[] HmacSHA1Encrypt(
String encryptText,
String encryptKey) throws Exception {
byte[] data = encryptKey.getBytes(ENCODING);
SecretKey secretKey = new SecretKeySpec(data, MAC_NAME);
Mac mac = Mac.getInstance(MAC_NAME);
mac.init(secretKey);
byte[] text = encryptText.getBytes(ENCODING);
byte[] digest = mac.doFinal(text);
return digest;
}
//实现java8的join函数
private static String join(String[] strs,String splitter) {
StringBuffer sb = new StringBuffer();
for(String s:strs){
sb.append(s+splitter);
}
return sb.toString().substring(0, sb.toString().length()-1);
}
/**
* get file's base64 string
* @param filePath file's path
* @return string
*/
public static String getBase64Str(String filePath){
byte[] readData = null;
String rtStr = "";
try
{
File file = new File(filePath);
FileInputStream fis = new FileInputStream(filePath);
if(fis != null && fis.getChannel() != null) {
readData = new byte[(int)file.length()];
int i = fis.read(readData);
fis.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
if (readData != null) {
rtStr = Base64.encodeToString(readData, Base64.NO_WRAP);
}
return rtStr;
}
博客简单记录了HmacSHA1和Base64在Android中的相关内容,虽未详细展开,但保留了相关信息。

1933

被折叠的 条评论
为什么被折叠?



