Java的Andr​​oid的URL加密 [英] java android URL encrypting

查看:96
本文介绍了Java的Andr​​oid的URL加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作将文件上载到Amazon S3(应用程序的一部分)的应用程序。但是,当我生成的文件的URL,它显示了认证密钥,文件名等。我需要加密的URL。另外我使用微小的网址缩短网址,但是当我把光标的链接,它显示了真正的URL。我找了MD5但我不能使它工作。请问有什么建议吗?

I am working on an application that uploads a file to amazon s3(part of the application). But when I generate the URL of the files, it shows the authentication key, file name and etc. I need to encrypt the URL. Also I am using tiny url to shorten the URL but when I put the curser on the link it shows the real URL. I looked for md5 but I couldn't make it work. Is there any suggestion?

推荐答案

我将试图解释MD5是如何工作的。

I will try to explain how MD5 works

import java.math.*;
import java.security.*;

public class testMain {

    /**
     * @param args
     */
    public static void main(String[] args) {

        String stringThatNeedsToBeEncrpyted = "yourURL"; // Value to encrypt
        MessageDigest mdEnc = null;
        try {
            mdEnc = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } // Encryption algorithm
        mdEnc.update(stringThatNeedsToBeEncrpyted.getBytes(), 0, stringThatNeedsToBeEncrpyted.length());
        String md5 = new BigInteger(1, mdEnc.digest()).toString(16); //Make the Encrypted string
        System.out.println(md5); //print the string in the console

    }   
}

输出是: 7f5976785d03c60f9fd4b08fb78e72ce

这是你的消息摘要。

修改

散列用户名和密码可以像PBKDF2,bcrypt或scrypt合适的哈希算法完成。而且始终使用SSL来传输机密数据。

Hashing a username and password should always be done with an appropriate hashing algorithm like PBKDF2, bcrypt or scrypt. Furthermore always use SSL to transfer confidential data.

这篇关于Java的Andr​​oid的URL加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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