android 字符串加解密算法

/** *加密 **/    private String encryptPassword(String clearText) {        try {            DESKeySpec keySpec = new DESKeySpec(                    BuildConfig.PASSWORD_ENC_SECRET.getBytes("UTF-8"));            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");            SecretKey key = keyFactory.generateSecret(keySpec);            Cipher cipher = Cipher.getInstance("DES");            cipher.init(Cipher.ENCRYPT_MODE, key);            String encrypedPwd = Base64.encodeToString(cipher.doFinal(clearText                    .getBytes("UTF-8")), Base64.DEFAULT);            return encrypedPwd;        } catch (Exception e) {        }        return clearText;    }/** *解密 **/    private String decryptPassword(String encryptedPwd) {        try {            DESKeySpec keySpec = new DESKeySpec(BuildConfig.PASSWORD_ENC_SECRET.getBytes("UTF-8"));            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");            SecretKey key = keyFactory.generateSecret(keySpec);            byte[] encryptedWithoutB64 = Base64.decode(encryptedPwd, Base64.DEFAULT);            Cipher cipher = Cipher.getInstance("DES");            cipher.init(Cipher.DECRYPT_MODE, key);            byte[] plainTextPwdBytes = cipher.doFinal(encryptedWithoutB64);            return new String(plainTextPwdBytes);        } catch (Exception e) {        }        return encryptedPwd;    }

更多相关文章

  1. 关于android xml文件中 android:id="@+id/my_button"的含义疑问
  2. 组件属性
  3. 利用 Android(安卓)Keystore 系统 加密存储和解密敏感信息
  4. 【Android(安卓)应用开发】Android资源文件 - 使用资源存储字符
  5. android 问题总结
  6. Android通过AES128加密解密字符串
  7. Android中的ClassLoader与dex文件加密实现分析
  8. 如何使用android中的搜索功能
  9. 2011.07.11(3)——— android xliff字符串操作

随机推荐

  1. Android中判断app是否连接网络
  2. Android installed app, never used, can
  3. android屏蔽返回键和Home键
  4. Android-微信抢红包插件-原理分析
  5. 【开发工具】判断请求源是 手机 or PC
  6. android具有折叠效果的控件
  7. Android中事件处理之TouchListener实现步
  8. AndroidManifest.xml文件详解(activity)(一)
  9. Android广播机制
  10. Android 实现windows文件资源管理器