zoukankan      html  css  js  c++  java
  • Android 对保存在 sharedpreference的重要数据进行编解码

    有时候为了登录方便会将用户名和密码保存在 sharedpreference里面,可是如果不加以处理密码将以明文保存。

    在Android中java层提供了工具类:android.util.Base64;用Base64对密码进行编码和解码。

     1 // Base64 编码:
     2 byte [] encode = Base64.encode("Hello, World".getBytes(), Base64.DEFAULT);
     3 
     4 String enc = new String(encode);
     5 
     6 Log.d("","base 64 encode = " + enc);
     7 
     8 // Base64 解码:
     9 byte [] result = Base64.decode("SGVsbG8sIFdvcmxk", Base64.DEFAULT);
    10 
    11 String res = new String(result);
    12 
    13 Log.d("", "base 64 result = " + res);

    例子演示了将"Hello, World"编码成"SGVsbG8sIFdvcmxk",然后又解码回来。

  • 相关阅读:
    python第一课
    go反射----4构建
    go反射----3方法
    go反射----2值
    go生成xml
    go互斥锁Mutex
    go中的读写锁RWMutex
    go语言调用cmd
    go语言发送邮件
    go语言文件操作
  • 原文地址:https://www.cnblogs.com/dj168/p/3956164.html
Copyright © 2011-2022 走看看