zoukankan      html  css  js  c++  java
  • Andriod 的 DES 加密

    1主要代码  

    关于  des 的导包 问题   要导  安卓本身的 64 位包  假设找com.sun.....可能会发生foundclass异常


    String key;
    public DES(String key)
    {

    this.key =key;
    }

    public String encrypt(String str) {

    byte[] enc = null;
    try {
    enc = desEncrypt(str, key);
    }
    catch (Exception ex) {
    }

    // return new com.e.text.BASE64Encoder().encode(enc);
    // return new BASE64Encoder().encode(enc);
    return new String (Base64.encode( enc, Base64.DEFAULT));
    }
    public static byte[] desEncrypt(String message, String key) throws Exception {
    Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

    DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));

    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
    IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
    cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);

    return cipher.doFinal(message.getBytes("UTF-8"));
    }

    附  demo 

    http://download.csdn.net/detail/wangchunshun/8180345


  • 相关阅读:
    saltstack配置管理之YAML(二)
    自动化运维之saltstack 简单用法(一)
    异常处理,枚举,泛型
    面向对象二
    面向对象
    python面向对象
    方法(函数),内存空间,数组
    for循环,while循环,do while循环
    if判断,switch语句
    运算符
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7065168.html
Copyright © 2011-2022 走看看