字节数组转换为Base64字符串中的Andr​​oid [英] convert byte array to Base64 String in android

查看:170
本文介绍了字节数组转换为Base64字符串中的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我必须输入用户密码,从Android应用程序来登记。

So I have the user enter password to signup from the android app.

在我的密码保存到我想将其转换为MD5单向哈希值,并将其保存到数据库服务器上的数据库中。

Before I save the password to the database on the server I want to convert it to a MD5 one way hash and save it to the database.

MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }
    try {
        md.update(password.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }
    byte raw[] = md.digest();

我怎么这个字节数组转换成Base64的字符串。我在一些论坛,Android的util包离开了,另一方面我看到在Android开发者网站的连接codetoString功能Base64编码和解码所看到的。

How do I convert this byte array to a Base64 string. I saw in some forum that android util package left out the Base64 encoding and decoding on the other hand I see the encodetoString function in the android developers site.

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

如果你希望你的应用程序,以低于API级别8兼容,那么你就可以在第三部分库来处理Base64编码拉。

If you want your application to be compatible below API level 8, then you can pull in a 3rd part library to handle the Base64 encoding.

Apache的共享codeC 是一个你可以试试。它包括一个Base64 codeC: HTTP://commons.apache .ORG / $ C $毫升/ API释放/ index.html的

Apache Commons Codec is one you can try. It includes a Base64 codec: http://commons.apache.org/codec/api-release/index.html.

这篇关于字节数组转换为Base64字符串中的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆