zoukankan      html  css  js  c++  java
  • android 字符串加解密算法

    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;
        }
  • 相关阅读:
    洛谷P2568 GCD
    线段树(模板)
    题解 CF1296D 【Fight with Monsters】
    图片针对父元素居中 TileImg
    npm
    echarts线图,柱状图,饼图option
    mac下修改环境变量
    input获取焦点,但不调起键盘
    mac shh 关联git仓库
    根据滚动条触发动画
  • 原文地址:https://www.cnblogs.com/allencoder/p/5327204.html
Copyright © 2011-2022 走看看