diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 739eded..885cc88 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -28,7 +28,10 @@
-
+
\ No newline at end of file
diff --git a/chat/src/main/java/com/example/chat/base/ChatApplication.java b/chat/src/main/java/com/example/chat/base/ChatApplication.java
index 934e9ee..8cab2ae 100644
--- a/chat/src/main/java/com/example/chat/base/ChatApplication.java
+++ b/chat/src/main/java/com/example/chat/base/ChatApplication.java
@@ -4,8 +4,6 @@
import android.app.Application;
import android.content.Context;
-import com.example.chat.base.ConstantUtil;
-import com.example.chat.base.RandomData;
import com.example.chat.bean.CustomInstallation;
import com.example.chat.dagger.ChatMainComponent;
import com.example.chat.dagger.ChatMainModule;
@@ -29,7 +27,6 @@
import java.util.Map;
import cn.bmob.push.BmobPush;
-import cn.bmob.v3.Bmob;
/**
* 项目名称: NewFastFrame
@@ -57,7 +54,6 @@ public static ChatMainComponent getChatMainComponent() {
public void onCreate(Application application) {
chatMainComponent = DaggerChatMainComponent.builder().appComponent(BaseApplication.getAppComponent())
.chatMainModule(new ChatMainModule()).build();
- Bmob.initialize(application, ConstantUtil.KEY);
// AppStat.i(ConstantUtil.KEY, null);
LogUtil.e("1服务器端初始化完成");
CustomInstallation customInstallation = new CustomInstallation();
diff --git a/chat/src/main/java/com/example/chat/base/ConstantUtil.java b/chat/src/main/java/com/example/chat/base/ConstantUtil.java
index 3778c25..1946dd2 100644
--- a/chat/src/main/java/com/example/chat/base/ConstantUtil.java
+++ b/chat/src/main/java/com/example/chat/base/ConstantUtil.java
@@ -109,7 +109,6 @@ public class ConstantUtil {
public static final int REQUEST_CODE_SELECT_FROM_LOCAL = 1;
public static final int REQUEST_CODE_LOCATION = 5;
// 4de21dc60adabe2dff4e81a3a592459f
- public static final String KEY = "06cefecaee1c01cac71cb2f7de18dc9c";
/**
* 系统通知ID
*/
diff --git a/chat/src/main/res/layout/activity_login.xml b/chat/src/main/res/layout/activity_login.xml
index 2099558..976e4b0 100644
--- a/chat/src/main/res/layout/activity_login.xml
+++ b/chat/src/main/res/layout/activity_login.xml
@@ -1,6 +1,6 @@
+ android:layout_height="match_parent">
headers) {
switchNum = 0;
this.url = url;
this.headers = headers;
+ BaseApplication.getVideoProxy().unregisterCacheListener(this);
return this;
}
@@ -136,6 +140,7 @@ public void setState(int state) {
@Override
public void start() {
+ CommonLogger.e("start");
ListVideoManager.getInstance().setCurrentPlayer(this);
if (mState == PLAY_STATE_IDLE || mState == PLAY_STATE_PREPARING) {
initMediaPlayer();
@@ -149,7 +154,7 @@ public void start() {
innerStart(mMediaPlayer.getCurrentPosition());
} else if (getCurrentState() == PLAY_STATE_ERROR || getCurrentState() == PLAY_STATE_FINISH) {
reset();
- prepareAsync();
+ start();
} else if (getCurrentState() == PLAY_STATE_PLAYING || getCurrentState() == PLAY_STATE_BUFFERING_PLAYING) {
}
@@ -338,17 +343,21 @@ public void reset() {
}
mState = PLAY_STATE_IDLE;
mVideoController.onPlayStateChanged(mState);
-
+ if (mSurfaceTexture != null) {
+ mSurfaceTexture.release();
+ mSurfaceTexture = null;
+ }
+ BaseApplication.getVideoProxy().unregisterCacheListener(this);
}
@Override
public void release() {
reset();
- if (mSurfaceTexture != null) {
- mSurfaceTexture.release();
- mSurfaceTexture = null;
- }
container.removeView(defaultTextureView);
+ if (mMediaPlayer != null) {
+ mMediaPlayer.release();
+ mMediaPlayer = null;
+ }
}
@Override
@@ -385,14 +394,25 @@ public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
}
}
- private void prepareAsync() {
- if (mMediaPlayer == null)
+ @Override
+ public void prepareAsync() {
+ CommonLogger.e("prepareAsync");
+ if (mMediaPlayer == null || url == null)
return;
container.setKeepScreenOn(true);
try {
mState = PLAY_STATE_PREPARING;
mVideoController.onPlayStateChanged(mState);
if (AppUtil.isNetworkAvailable()) {
+ // String realUrl;
+ // if (url.startsWith("http")) {
+ // realUrl = BaseApplication.getVideoProxy().getProxyUrl(url);
+ // CommonLogger.e("proxyUrl:" + realUrl);
+ // BaseApplication.getVideoProxy().registerCacheListener(this, url);
+ // } else {
+ // realUrl = url;
+ // mBufferedPercent = 100;
+ // }
mMediaPlayer.setDataSource(getContext(), Uri.parse(url), headers);
mMediaPlayer.prepareAsync();
} else {
@@ -430,6 +450,7 @@ private void innerStart(long position) {
@Override
public void onPrepared(IMediaPlayer iMediaPlayer) {
+ CommonLogger.e("onPrepared");
mState = PLAY_STATE_PREPARED;
mVideoController.onPlayStateChanged(mState);
long position = 0;
@@ -493,7 +514,6 @@ public boolean onError(IMediaPlayer iMediaPlayer, int what, int extra) {
if ((what == 1 && extra == -2147483648) && !url.contains(".mp4") && !url.contains(".m3u8") && switchNum < MAX_SWITCH_NUM) {
switchNum++;
switchMediaPlayer(false);
- return true;
}
mState = PLAY_STATE_ERROR;
mVideoController.onPlayStateChanged(mState);
@@ -529,4 +549,20 @@ public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int width, int height,
public void setSwitchFlag(boolean isSwitch) {
this.isSwitch = isSwitch;
}
+
+ @Override
+ public void onCacheAvailable(File cacheFile, String url, int percentsAvailable) {
+ CommonLogger.e("缓存文件:" + cacheFile.getAbsolutePath() + "\n" +
+ "缓存url:" + url + "\n"
+ + "缓存进度:" + percentsAvailable);
+ mBufferedPercent = percentsAvailable;
+ if (percentsAvailable == 100) {
+ VideoInfoBean videoInfoBean = new VideoInfoBean();
+ videoInfoBean.setUrl(url);
+ videoInfoBean.setPath(cacheFile.getAbsolutePath());
+ videoInfoBean.setName(getTitle());
+ BaseApplication.getAppComponent().getDaoSession()
+ .getVideoInfoBeanDao().insertOrReplace(videoInfoBean);
+ }
+ }
}
diff --git a/commonlibrary/src/main/java/com/example/commonlibrary/net/TrustAllCerts.java b/commonlibrary/src/main/java/com/example/commonlibrary/net/okhttpconfig/TrustAllCerts.java
similarity index 96%
rename from commonlibrary/src/main/java/com/example/commonlibrary/net/TrustAllCerts.java
rename to commonlibrary/src/main/java/com/example/commonlibrary/net/okhttpconfig/TrustAllCerts.java
index 8bbe7d1..0d75cd7 100644
--- a/commonlibrary/src/main/java/com/example/commonlibrary/net/TrustAllCerts.java
+++ b/commonlibrary/src/main/java/com/example/commonlibrary/net/okhttpconfig/TrustAllCerts.java
@@ -1,4 +1,4 @@
-package com.example.commonlibrary.net;
+package com.example.commonlibrary.net.okhttpconfig;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
diff --git a/commonlibrary/src/main/java/com/example/commonlibrary/skin/SkinManager.java b/commonlibrary/src/main/java/com/example/commonlibrary/skin/SkinManager.java
index 5dfda92..eb15017 100644
--- a/commonlibrary/src/main/java/com/example/commonlibrary/skin/SkinManager.java
+++ b/commonlibrary/src/main/java/com/example/commonlibrary/skin/SkinManager.java
@@ -15,7 +15,6 @@
import com.example.commonlibrary.net.download.DownloadListener;
import com.example.commonlibrary.rxbus.RxBusManager;
import com.example.commonlibrary.rxbus.event.SkinUpdateEvent;
-import com.example.commonlibrary.utils.CommonLogger;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -84,7 +83,7 @@ public void loadSkinResource(String path, final DownloadListener listener) {
public void updateSkin(String path,SkinUpdateListener skinUpdateListener) {
try {
- CommonLogger.e("path:" +path);
+
PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
packageName = packageInfo.packageName;
isLocal = false;
@@ -158,7 +157,6 @@ public Drawable getDrawable(int resId) {
public ColorStateList getColorStateList(int resId) {
if (isLocal) {
- CommonLogger.e("放回本地");
return ContextCompat.getColorStateList(context, resId);
}
int id = resources.getIdentifier(context.getResources().getResourceEntryName(resId), "color", packageName);
diff --git a/commonlibrary/src/main/java/com/example/commonlibrary/utils/AppUtil.java b/commonlibrary/src/main/java/com/example/commonlibrary/utils/AppUtil.java
index 8e36f93..91cadd8 100644
--- a/commonlibrary/src/main/java/com/example/commonlibrary/utils/AppUtil.java
+++ b/commonlibrary/src/main/java/com/example/commonlibrary/utils/AppUtil.java
@@ -17,6 +17,8 @@
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -54,6 +56,25 @@ public static boolean isNetworkAvailable() {
}
+ public static String md5(String string) {
+ try {
+ MessageDigest messageDigest = MessageDigest.getInstance("MD5");
+ byte[] digestBytes = messageDigest.digest(string.getBytes());
+ return bytesToHexString(digestBytes);
+ } catch (NoSuchAlgorithmException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private static String bytesToHexString(byte[] bytes) {
+ StringBuffer sb = new StringBuffer();
+ for (byte b : bytes) {
+ sb.append(String.format("%02x", b));
+ }
+ return sb.toString();
+ }
+
+
public static boolean checkPackInfo(Context context, String packageName) {
PackageInfo packageInfo = null;
try {
diff --git a/commonlibrary/src/main/java/com/example/commonlibrary/utils/Constant.java b/commonlibrary/src/main/java/com/example/commonlibrary/utils/Constant.java
index da23a15..ae0c0b6 100644
--- a/commonlibrary/src/main/java/com/example/commonlibrary/utils/Constant.java
+++ b/commonlibrary/src/main/java/com/example/commonlibrary/utils/Constant.java
@@ -31,6 +31,7 @@ public class Constant {
public static final String RECENT_SONG_URL_LIST = "recent_song_list";
public static final String VIEW = "view";
public static final String FLAG = "flag";
+ public static final String KEY = "06cefecaee1c01cac71cb2f7de18dc9c";
private static final String BASE_CACHE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "common" + File.separator;
/**
* 声音的缓存目录
diff --git a/commonlibrary/src/main/java/com/example/commonlibrary/utils/EncryptUtils.java b/commonlibrary/src/main/java/com/example/commonlibrary/utils/EncryptUtils.java
new file mode 100644
index 0000000..e106c87
--- /dev/null
+++ b/commonlibrary/src/main/java/com/example/commonlibrary/utils/EncryptUtils.java
@@ -0,0 +1,1203 @@
+package com.example.commonlibrary.utils;
+
+import android.util.Base64;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.DigestInputStream;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.KeyFactory;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.Mac;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * 项目名称: NewFastFrame
+ * 创建人: 陈锦军
+ * 创建时间: 2019/1/8 18:23
+ */
+public final class EncryptUtils {
+
+ private EncryptUtils() {
+ throw new UnsupportedOperationException("u can't instantiate me...");
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // hash encryption
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Return the hex string of MD2 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of MD2 encryption
+ */
+ public static String encryptMD2ToString(final String data) {
+ if (data == null || data.length() == 0) return "";
+ return encryptMD2ToString(data.getBytes());
+ }
+
+ /**
+ * Return the hex string of MD2 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of MD2 encryption
+ */
+ public static String encryptMD2ToString(final byte[] data) {
+ return bytes2HexString(encryptMD2(data));
+ }
+
+ /**
+ * Return the bytes of MD2 encryption.
+ *
+ * @param data The data.
+ * @return the bytes of MD2 encryption
+ */
+ public static byte[] encryptMD2(final byte[] data) {
+ return hashTemplate(data, "MD2");
+ }
+
+ /**
+ * Return the hex string of MD5 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of MD5 encryption
+ */
+ public static String encryptMD5ToString(final String data) {
+ if (data == null || data.length() == 0) return "";
+ return encryptMD5ToString(data.getBytes());
+ }
+
+ /**
+ * Return the hex string of MD5 encryption.
+ *
+ * @param data The data.
+ * @param salt The salt.
+ * @return the hex string of MD5 encryption
+ */
+ public static String encryptMD5ToString(final String data, final String salt) {
+ if (data == null && salt == null) return "";
+ if (salt == null) return bytes2HexString(encryptMD5(data.getBytes()));
+ if (data == null) return bytes2HexString(encryptMD5(salt.getBytes()));
+ return bytes2HexString(encryptMD5((data + salt).getBytes()));
+ }
+
+ /**
+ * Return the hex string of MD5 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of MD5 encryption
+ */
+ public static String encryptMD5ToString(final byte[] data) {
+ return bytes2HexString(encryptMD5(data));
+ }
+
+ /**
+ * Return the hex string of MD5 encryption.
+ *
+ * @param data The data.
+ * @param salt The salt.
+ * @return the hex string of MD5 encryption
+ */
+ public static String encryptMD5ToString(final byte[] data, final byte[] salt) {
+ if (data == null && salt == null) return "";
+ if (salt == null) return bytes2HexString(encryptMD5(data));
+ if (data == null) return bytes2HexString(encryptMD5(salt));
+ byte[] dataSalt = new byte[data.length + salt.length];
+ System.arraycopy(data, 0, dataSalt, 0, data.length);
+ System.arraycopy(salt, 0, dataSalt, data.length, salt.length);
+ return bytes2HexString(encryptMD5(dataSalt));
+ }
+
+ /**
+ * Return the bytes of MD5 encryption.
+ *
+ * @param data The data.
+ * @return the bytes of MD5 encryption
+ */
+ public static byte[] encryptMD5(final byte[] data) {
+ return hashTemplate(data, "MD5");
+ }
+
+ /**
+ * Return the hex string of file's MD5 encryption.
+ *
+ * @param filePath The path of file.
+ * @return the hex string of file's MD5 encryption
+ */
+ public static String encryptMD5File2String(final String filePath) {
+ File file = isSpace(filePath) ? null : new File(filePath);
+ return encryptMD5File2String(file);
+ }
+
+ /**
+ * Return the bytes of file's MD5 encryption.
+ *
+ * @param filePath The path of file.
+ * @return the bytes of file's MD5 encryption
+ */
+ public static byte[] encryptMD5File(final String filePath) {
+ File file = isSpace(filePath) ? null : new File(filePath);
+ return encryptMD5File(file);
+ }
+
+ /**
+ * Return the hex string of file's MD5 encryption.
+ *
+ * @param file The file.
+ * @return the hex string of file's MD5 encryption
+ */
+ public static String encryptMD5File2String(final File file) {
+ return bytes2HexString(encryptMD5File(file));
+ }
+
+ /**
+ * Return the bytes of file's MD5 encryption.
+ *
+ * @param file The file.
+ * @return the bytes of file's MD5 encryption
+ */
+ public static byte[] encryptMD5File(final File file) {
+ if (file == null) return null;
+ FileInputStream fis = null;
+ DigestInputStream digestInputStream;
+ try {
+ fis = new FileInputStream(file);
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ digestInputStream = new DigestInputStream(fis, md);
+ byte[] buffer = new byte[256 * 1024];
+ while (true) {
+ if (!(digestInputStream.read(buffer) > 0)) break;
+ }
+ md = digestInputStream.getMessageDigest();
+ return md.digest();
+ } catch (NoSuchAlgorithmException | IOException e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ try {
+ if (fis != null) {
+ fis.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Return the hex string of SHA1 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA1 encryption
+ */
+ public static String encryptSHA1ToString(final String data) {
+ if (data == null || data.length() == 0) return "";
+ return encryptSHA1ToString(data.getBytes());
+ }
+
+ /**
+ * Return the hex string of SHA1 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA1 encryption
+ */
+ public static String encryptSHA1ToString(final byte[] data) {
+ return bytes2HexString(encryptSHA1(data));
+ }
+
+ /**
+ * Return the bytes of SHA1 encryption.
+ *
+ * @param data The data.
+ * @return the bytes of SHA1 encryption
+ */
+ public static byte[] encryptSHA1(final byte[] data) {
+ return hashTemplate(data, "SHA-1");
+ }
+
+ /**
+ * Return the hex string of SHA224 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA224 encryption
+ */
+ public static String encryptSHA224ToString(final String data) {
+ if (data == null || data.length() == 0) return "";
+ return encryptSHA224ToString(data.getBytes());
+ }
+
+ /**
+ * Return the hex string of SHA224 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA224 encryption
+ */
+ public static String encryptSHA224ToString(final byte[] data) {
+ return bytes2HexString(encryptSHA224(data));
+ }
+
+ /**
+ * Return the bytes of SHA224 encryption.
+ *
+ * @param data The data.
+ * @return the bytes of SHA224 encryption
+ */
+ public static byte[] encryptSHA224(final byte[] data) {
+ return hashTemplate(data, "SHA224");
+ }
+
+ /**
+ * Return the hex string of SHA256 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA256 encryption
+ */
+ public static String encryptSHA256ToString(final String data) {
+ if (data == null || data.length() == 0) return "";
+ return encryptSHA256ToString(data.getBytes());
+ }
+
+ /**
+ * Return the hex string of SHA256 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA256 encryption
+ */
+ public static String encryptSHA256ToString(final byte[] data) {
+ return bytes2HexString(encryptSHA256(data));
+ }
+
+ /**
+ * Return the bytes of SHA256 encryption.
+ *
+ * @param data The data.
+ * @return the bytes of SHA256 encryption
+ */
+ public static byte[] encryptSHA256(final byte[] data) {
+ return hashTemplate(data, "SHA-256");
+ }
+
+ /**
+ * Return the hex string of SHA384 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA384 encryption
+ */
+ public static String encryptSHA384ToString(final String data) {
+ if (data == null || data.length() == 0) return "";
+ return encryptSHA384ToString(data.getBytes());
+ }
+
+ /**
+ * Return the hex string of SHA384 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA384 encryption
+ */
+ public static String encryptSHA384ToString(final byte[] data) {
+ return bytes2HexString(encryptSHA384(data));
+ }
+
+ /**
+ * Return the bytes of SHA384 encryption.
+ *
+ * @param data The data.
+ * @return the bytes of SHA384 encryption
+ */
+ public static byte[] encryptSHA384(final byte[] data) {
+ return hashTemplate(data, "SHA-384");
+ }
+
+ /**
+ * Return the hex string of SHA512 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA512 encryption
+ */
+ public static String encryptSHA512ToString(final String data) {
+ if (data == null || data.length() == 0) return "";
+ return encryptSHA512ToString(data.getBytes());
+ }
+
+ /**
+ * Return the hex string of SHA512 encryption.
+ *
+ * @param data The data.
+ * @return the hex string of SHA512 encryption
+ */
+ public static String encryptSHA512ToString(final byte[] data) {
+ return bytes2HexString(encryptSHA512(data));
+ }
+
+ /**
+ * Return the bytes of SHA512 encryption.
+ *
+ * @param data The data.
+ * @return the bytes of SHA512 encryption
+ */
+ public static byte[] encryptSHA512(final byte[] data) {
+ return hashTemplate(data, "SHA-512");
+ }
+
+ /**
+ * Return the bytes of hash encryption.
+ *
+ * @param data The data.
+ * @param algorithm The name of hash encryption.
+ * @return the bytes of hash encryption
+ */
+ private static byte[] hashTemplate(final byte[] data, final String algorithm) {
+ if (data == null || data.length <= 0) return null;
+ try {
+ MessageDigest md = MessageDigest.getInstance(algorithm);
+ md.update(data);
+ return md.digest();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // hmac encryption
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Return the hex string of HmacMD5 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacMD5 encryption
+ */
+ public static String encryptHmacMD5ToString(final String data, final String key) {
+ if (data == null || data.length() == 0 || key == null || key.length() == 0) return "";
+ return encryptHmacMD5ToString(data.getBytes(), key.getBytes());
+ }
+
+ /**
+ * Return the hex string of HmacMD5 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacMD5 encryption
+ */
+ public static String encryptHmacMD5ToString(final byte[] data, final byte[] key) {
+ return bytes2HexString(encryptHmacMD5(data, key));
+ }
+
+ /**
+ * Return the bytes of HmacMD5 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the bytes of HmacMD5 encryption
+ */
+ public static byte[] encryptHmacMD5(final byte[] data, final byte[] key) {
+ return hmacTemplate(data, key, "HmacMD5");
+ }
+
+ /**
+ * Return the hex string of HmacSHA1 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA1 encryption
+ */
+ public static String encryptHmacSHA1ToString(final String data, final String key) {
+ if (data == null || data.length() == 0 || key == null || key.length() == 0) return "";
+ return encryptHmacSHA1ToString(data.getBytes(), key.getBytes());
+ }
+
+ /**
+ * Return the hex string of HmacSHA1 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA1 encryption
+ */
+ public static String encryptHmacSHA1ToString(final byte[] data, final byte[] key) {
+ return bytes2HexString(encryptHmacSHA1(data, key));
+ }
+
+ /**
+ * Return the bytes of HmacSHA1 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the bytes of HmacSHA1 encryption
+ */
+ public static byte[] encryptHmacSHA1(final byte[] data, final byte[] key) {
+ return hmacTemplate(data, key, "HmacSHA1");
+ }
+
+ /**
+ * Return the hex string of HmacSHA224 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA224 encryption
+ */
+ public static String encryptHmacSHA224ToString(final String data, final String key) {
+ if (data == null || data.length() == 0 || key == null || key.length() == 0) return "";
+ return encryptHmacSHA224ToString(data.getBytes(), key.getBytes());
+ }
+
+ /**
+ * Return the hex string of HmacSHA224 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA224 encryption
+ */
+ public static String encryptHmacSHA224ToString(final byte[] data, final byte[] key) {
+ return bytes2HexString(encryptHmacSHA224(data, key));
+ }
+
+ /**
+ * Return the bytes of HmacSHA224 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the bytes of HmacSHA224 encryption
+ */
+ public static byte[] encryptHmacSHA224(final byte[] data, final byte[] key) {
+ return hmacTemplate(data, key, "HmacSHA224");
+ }
+
+ /**
+ * Return the hex string of HmacSHA256 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA256 encryption
+ */
+ public static String encryptHmacSHA256ToString(final String data, final String key) {
+ if (data == null || data.length() == 0 || key == null || key.length() == 0) return "";
+ return encryptHmacSHA256ToString(data.getBytes(), key.getBytes());
+ }
+
+ /**
+ * Return the hex string of HmacSHA256 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA256 encryption
+ */
+ public static String encryptHmacSHA256ToString(final byte[] data, final byte[] key) {
+ return bytes2HexString(encryptHmacSHA256(data, key));
+ }
+
+ /**
+ * Return the bytes of HmacSHA256 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the bytes of HmacSHA256 encryption
+ */
+ public static byte[] encryptHmacSHA256(final byte[] data, final byte[] key) {
+ return hmacTemplate(data, key, "HmacSHA256");
+ }
+
+ /**
+ * Return the hex string of HmacSHA384 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA384 encryption
+ */
+ public static String encryptHmacSHA384ToString(final String data, final String key) {
+ if (data == null || data.length() == 0 || key == null || key.length() == 0) return "";
+ return encryptHmacSHA384ToString(data.getBytes(), key.getBytes());
+ }
+
+ /**
+ * Return the hex string of HmacSHA384 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA384 encryption
+ */
+ public static String encryptHmacSHA384ToString(final byte[] data, final byte[] key) {
+ return bytes2HexString(encryptHmacSHA384(data, key));
+ }
+
+ /**
+ * Return the bytes of HmacSHA384 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the bytes of HmacSHA384 encryption
+ */
+ public static byte[] encryptHmacSHA384(final byte[] data, final byte[] key) {
+ return hmacTemplate(data, key, "HmacSHA384");
+ }
+
+ /**
+ * Return the hex string of HmacSHA512 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA512 encryption
+ */
+ public static String encryptHmacSHA512ToString(final String data, final String key) {
+ if (data == null || data.length() == 0 || key == null || key.length() == 0) return "";
+ return encryptHmacSHA512ToString(data.getBytes(), key.getBytes());
+ }
+
+ /**
+ * Return the hex string of HmacSHA512 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the hex string of HmacSHA512 encryption
+ */
+ public static String encryptHmacSHA512ToString(final byte[] data, final byte[] key) {
+ return bytes2HexString(encryptHmacSHA512(data, key));
+ }
+
+ /**
+ * Return the bytes of HmacSHA512 encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @return the bytes of HmacSHA512 encryption
+ */
+ public static byte[] encryptHmacSHA512(final byte[] data, final byte[] key) {
+ return hmacTemplate(data, key, "HmacSHA512");
+ }
+
+ /**
+ * Return the bytes of hmac encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param algorithm The name of hmac encryption.
+ * @return the bytes of hmac encryption
+ */
+ private static byte[] hmacTemplate(final byte[] data,
+ final byte[] key,
+ final String algorithm) {
+ if (data == null || data.length == 0 || key == null || key.length == 0) return null;
+ try {
+ SecretKeySpec secretKey = new SecretKeySpec(key, algorithm);
+ Mac mac = Mac.getInstance(algorithm);
+ mac.init(secretKey);
+ return mac.doFinal(data);
+ } catch (InvalidKeyException | NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // DES encryption
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Return the Base64-encode bytes of DES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the Base64-encode bytes of DES encryption
+ */
+ public static byte[] encryptDES2Base64(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return base64Encode(encryptDES(data, key, transformation, iv));
+ }
+
+ /**
+ * Return the hex string of DES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the hex string of DES encryption
+ */
+ public static String encryptDES2HexString(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return bytes2HexString(encryptDES(data, key, transformation, iv));
+ }
+
+ /**
+ * Return the bytes of DES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of DES encryption
+ */
+ public static byte[] encryptDES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return symmetricTemplate(data, key, "DES", transformation, iv, true);
+ }
+
+ /**
+ * Return the bytes of DES decryption for Base64-encode bytes.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of DES decryption for Base64-encode bytes
+ */
+ public static byte[] decryptBase64DES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return decryptDES(base64Decode(data), key, transformation, iv);
+ }
+
+ /**
+ * Return the bytes of DES decryption for hex string.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of DES decryption for hex string
+ */
+ public static byte[] decryptHexStringDES(final String data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return decryptDES(hexString2Bytes(data), key, transformation, iv);
+ }
+
+ /**
+ * Return the bytes of DES decryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of DES decryption
+ */
+ public static byte[] decryptDES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return symmetricTemplate(data, key, "DES", transformation, iv, false);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // 3DES encryption
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Return the Base64-encode bytes of 3DES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the Base64-encode bytes of 3DES encryption
+ */
+ public static byte[] encrypt3DES2Base64(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return base64Encode(encrypt3DES(data, key, transformation, iv));
+ }
+
+ /**
+ * Return the hex string of 3DES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the hex string of 3DES encryption
+ */
+ public static String encrypt3DES2HexString(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return bytes2HexString(encrypt3DES(data, key, transformation, iv));
+ }
+
+ /**
+ * Return the bytes of 3DES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of 3DES encryption
+ */
+ public static byte[] encrypt3DES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return symmetricTemplate(data, key, "DESede", transformation, iv, true);
+ }
+
+ /**
+ * Return the bytes of 3DES decryption for Base64-encode bytes.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of 3DES decryption for Base64-encode bytes
+ */
+ public static byte[] decryptBase64_3DES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return decrypt3DES(base64Decode(data), key, transformation, iv);
+ }
+
+ /**
+ * Return the bytes of 3DES decryption for hex string.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of 3DES decryption for hex string
+ */
+ public static byte[] decryptHexString3DES(final String data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return decrypt3DES(hexString2Bytes(data), key, transformation, iv);
+ }
+
+ /**
+ * Return the bytes of 3DES decryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of 3DES decryption
+ */
+ public static byte[] decrypt3DES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return symmetricTemplate(data, key, "DESede", transformation, iv, false);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // AES encryption
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Return the Base64-encode bytes of AES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the Base64-encode bytes of AES encryption
+ */
+ public static byte[] encryptAES2Base64(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return base64Encode(encryptAES(data, key, transformation, iv));
+ }
+
+ /**
+ * Return the hex string of AES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the hex string of AES encryption
+ */
+ public static String encryptAES2HexString(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return bytes2HexString(encryptAES(data, key, transformation, iv));
+ }
+
+ /**
+ * Return the bytes of AES encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of AES encryption
+ */
+ public static byte[] encryptAES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return symmetricTemplate(data, key, "AES", transformation, iv, true);
+ }
+
+ /**
+ * Return the bytes of AES decryption for Base64-encode bytes.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of AES decryption for Base64-encode bytes
+ */
+ public static byte[] decryptBase64AES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return decryptAES(base64Decode(data), key, transformation, iv);
+ }
+
+ /**
+ * Return the bytes of AES decryption for hex string.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of AES decryption for hex string
+ */
+ public static byte[] decryptHexStringAES(final String data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return decryptAES(hexString2Bytes(data), key, transformation, iv);
+ }
+
+ /**
+ * Return the bytes of AES decryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param iv The buffer with the IV. The contents of the
+ * buffer are copied to protect against subsequent modification.
+ * @return the bytes of AES decryption
+ */
+ public static byte[] decryptAES(final byte[] data,
+ final byte[] key,
+ final String transformation,
+ final byte[] iv) {
+ return symmetricTemplate(data, key, "AES", transformation, iv, false);
+ }
+
+ /**
+ * Return the bytes of symmetric encryption or decryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param algorithm The name of algorithm.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS5Padding.
+ * @param isEncrypt True to encrypt, false otherwise.
+ * @return the bytes of symmetric encryption or decryption
+ */
+ private static byte[] symmetricTemplate(final byte[] data,
+ final byte[] key,
+ final String algorithm,
+ final String transformation,
+ final byte[] iv,
+ final boolean isEncrypt) {
+ if (data == null || data.length == 0 || key == null || key.length == 0) return null;
+ try {
+ SecretKey secretKey;
+ if ("DES".equals(algorithm)) {
+ DESKeySpec desKey = new DESKeySpec(key);
+ SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
+ secretKey = keyFactory.generateSecret(desKey);
+ } else {
+ secretKey = new SecretKeySpec(key, algorithm);
+ }
+ Cipher cipher = Cipher.getInstance(transformation);
+ if (iv == null || iv.length == 0) {
+ cipher.init(isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, secretKey);
+ } else {
+ AlgorithmParameterSpec params = new IvParameterSpec(iv);
+ cipher.init(isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, secretKey, params);
+ }
+ return cipher.doFinal(data);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // RSA encryption
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Return the Base64-encode bytes of RSA encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param isPublicKey True to use public key, false to use private key.
+ * @param transformation The name of the transformation, e.g., RSA/CBC/PKCS1Padding.
+ * @return the Base64-encode bytes of RSA encryption
+ */
+ public static byte[] encryptRSA2Base64(final byte[] data,
+ final byte[] key,
+ final boolean isPublicKey,
+ final String transformation) {
+ return base64Encode(encryptRSA(data, key, isPublicKey, transformation));
+ }
+
+ /**
+ * Return the hex string of RSA encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param isPublicKey True to use public key, false to use private key.
+ * @param transformation The name of the transformation, e.g., RSA/CBC/PKCS1Padding.
+ * @return the hex string of RSA encryption
+ */
+ public static String encryptRSA2HexString(final byte[] data,
+ final byte[] key,
+ final boolean isPublicKey,
+ final String transformation) {
+ return bytes2HexString(encryptRSA(data, key, isPublicKey, transformation));
+ }
+
+ /**
+ * Return the bytes of RSA encryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param isPublicKey True to use public key, false to use private key.
+ * @param transformation The name of the transformation, e.g., RSA/CBC/PKCS1Padding.
+ * @return the bytes of RSA encryption
+ */
+ public static byte[] encryptRSA(final byte[] data,
+ final byte[] key,
+ final boolean isPublicKey,
+ final String transformation) {
+ return rsaTemplate(data, key, isPublicKey, transformation, true);
+ }
+
+ /**
+ * Return the bytes of RSA decryption for Base64-encode bytes.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param isPublicKey True to use public key, false to use private key.
+ * @param transformation The name of the transformation, e.g., RSA/CBC/PKCS1Padding.
+ * @return the bytes of RSA decryption for Base64-encode bytes
+ */
+ public static byte[] decryptBase64RSA(final byte[] data,
+ final byte[] key,
+ final boolean isPublicKey,
+ final String transformation) {
+ return decryptRSA(base64Decode(data), key, isPublicKey, transformation);
+ }
+
+ /**
+ * Return the bytes of RSA decryption for hex string.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param isPublicKey True to use public key, false to use private key.
+ * @param transformation The name of the transformation, e.g., RSA/CBC/PKCS1Padding.
+ * @return the bytes of RSA decryption for hex string
+ */
+ public static byte[] decryptHexStringRSA(final String data,
+ final byte[] key,
+ final boolean isPublicKey,
+ final String transformation) {
+ return decryptRSA(hexString2Bytes(data), key, isPublicKey, transformation);
+ }
+
+ /**
+ * Return the bytes of RSA decryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param isPublicKey True to use public key, false to use private key.
+ * @param transformation The name of the transformation, e.g., RSA/CBC/PKCS1Padding.
+ * @return the bytes of RSA decryption
+ */
+ public static byte[] decryptRSA(final byte[] data,
+ final byte[] key,
+ final boolean isPublicKey,
+ final String transformation) {
+ return rsaTemplate(data, key, isPublicKey, transformation, false);
+ }
+
+ /**
+ * Return the bytes of RSA encryption or decryption.
+ *
+ * @param data The data.
+ * @param key The key.
+ * @param isPublicKey True to use public key, false to use private key.
+ * @param transformation The name of the transformation, e.g., DES/CBC/PKCS1Padding.
+ * @param isEncrypt True to encrypt, false otherwise.
+ * @return the bytes of RSA encryption or decryption
+ */
+ private static byte[] rsaTemplate(final byte[] data,
+ final byte[] key,
+ final boolean isPublicKey,
+ final String transformation,
+ final boolean isEncrypt) {
+ if (data == null || data.length == 0 || key == null || key.length == 0) {
+ return null;
+ }
+ try {
+ Key rsaKey;
+ if (isPublicKey) {
+ X509EncodedKeySpec keySpec = new X509EncodedKeySpec(key);
+ rsaKey = KeyFactory.getInstance("RSA").generatePublic(keySpec);
+ } else {
+ PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(key);
+ rsaKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
+ }
+ if (rsaKey == null) return null;
+ Cipher cipher = Cipher.getInstance(transformation);
+ cipher.init(isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, rsaKey);
+ int len = data.length;
+ int maxLen = isEncrypt ? 117 : 128;
+ int count = len / maxLen;
+ if (count > 0) {
+ byte[] ret = new byte[0];
+ byte[] buff = new byte[maxLen];
+ int index = 0;
+ for (int i = 0; i < count; i++) {
+ System.arraycopy(data, index, buff, 0, maxLen);
+ ret = joins(ret, cipher.doFinal(buff));
+ index += maxLen;
+ }
+ if (index != len) {
+ int restLen = len - index;
+ buff = new byte[restLen];
+ System.arraycopy(data, index, buff, 0, restLen);
+ ret = joins(ret, cipher.doFinal(buff));
+ }
+ return ret;
+ } else {
+ return cipher.doFinal(data);
+ }
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (NoSuchPaddingException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (BadPaddingException e) {
+ e.printStackTrace();
+ } catch (IllegalBlockSizeException e) {
+ e.printStackTrace();
+ } catch (InvalidKeySpecException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // other utils methods
+ ///////////////////////////////////////////////////////////////////////////
+
+ private static byte[] joins(final byte[] prefix, final byte[] suffix) {
+ byte[] ret = new byte[prefix.length + suffix.length];
+ System.arraycopy(prefix, 0, ret, 0, prefix.length);
+ System.arraycopy(suffix, 0, ret, prefix.length, suffix.length);
+ return ret;
+ }
+
+ private static final char HEX_DIGITS[] =
+ {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+
+ private static String bytes2HexString(final byte[] bytes) {
+ if (bytes == null) return "";
+ int len = bytes.length;
+ if (len <= 0) return "";
+ char[] ret = new char[len << 1];
+ for (int i = 0, j = 0; i < len; i++) {
+ ret[j++] = HEX_DIGITS[bytes[i] >> 4 & 0x0f];
+ ret[j++] = HEX_DIGITS[bytes[i] & 0x0f];
+ }
+ return new String(ret);
+ }
+
+ private static byte[] hexString2Bytes(String hexString) {
+ if (isSpace(hexString)) return null;
+ int len = hexString.length();
+ if (len % 2 != 0) {
+ hexString = "0" + hexString;
+ len = len + 1;
+ }
+ char[] hexBytes = hexString.toUpperCase().toCharArray();
+ byte[] ret = new byte[len >> 1];
+ for (int i = 0; i < len; i += 2) {
+ ret[i >> 1] = (byte) (hex2Dec(hexBytes[i]) << 4 | hex2Dec(hexBytes[i + 1]));
+ }
+ return ret;
+ }
+
+ private static int hex2Dec(final char hexChar) {
+ if (hexChar >= '0' && hexChar <= '9') {
+ return hexChar - '0';
+ } else if (hexChar >= 'A' && hexChar <= 'F') {
+ return hexChar - 'A' + 10;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ private static byte[] base64Encode(final byte[] input) {
+ return Base64.encode(input, Base64.NO_WRAP);
+ }
+
+ private static byte[] base64Decode(final byte[] input) {
+ return Base64.decode(input, Base64.NO_WRAP);
+ }
+
+ private static boolean isSpace(final String s) {
+ if (s == null) return true;
+ for (int i = 0, len = s.length(); i < len; ++i) {
+ if (!Character.isWhitespace(s.charAt(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/commonlibrary/src/main/java/com/example/commonlibrary/utils/FileUtil.java b/commonlibrary/src/main/java/com/example/commonlibrary/utils/FileUtil.java
index 2275043..9ca577a 100644
--- a/commonlibrary/src/main/java/com/example/commonlibrary/utils/FileUtil.java
+++ b/commonlibrary/src/main/java/com/example/commonlibrary/utils/FileUtil.java
@@ -41,6 +41,9 @@ public static File getDefaultCacheFile(Context context) {
}
+
+
+
private static String getCacheFilePath(Context context) {
String packageName = context.getPackageName();
return "/mnt/sdcard/" + packageName;
diff --git a/news/src/main/java/com/example/video/api/OtherNewsApi.java b/news/src/main/java/com/example/video/api/OtherNewsApi.java
index 3f19920..5564ec3 100644
--- a/news/src/main/java/com/example/video/api/OtherNewsApi.java
+++ b/news/src/main/java/com/example/video/api/OtherNewsApi.java
@@ -45,6 +45,7 @@ Observable
diff --git a/video/src/main/res/layout/view_activity_video_header.xml b/video/src/main/res/layout/view_activity_video_header.xml
new file mode 100644
index 0000000..fd79367
--- /dev/null
+++ b/video/src/main/res/layout/view_activity_video_header.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
\ No newline at end of file