如何从byte []的URL到servlet获取参数?

时间:2017-03-02 06:52:15

标签: java servlets

需要你的帮助

我发送确认链接到邮件ID以激活,在url中发送用户名,所以我已将String用户名加密为byte []

http://localhost:8080/link_expiry/Acct_pen?uname=[B@11d42b72&pt=1488436457838 

正如您所注意到的,我在url中的用户名已加密,问题是????

如何获取byte []的用户名到servlet以验证用户..

 KeyGenerator keygenerator = KeyGenerator.getInstance("DES");
             SecretKey myDesKey = keygenerator.generateKey();
             Cipher desCipher;
             desCipher = Cipher.getInstance("DES");

        /*  **String uname=request.getParameter("uname");
            System.out.println("username from link" +uname); */**

            byte[] ci=uname.getBytes();
            System.out.println("byte[] ci"+ci);
            desCipher.init(Cipher.DECRYPT_MODE, myDesKey);
             byte[] textDecrypted = desCipher.doFinal(ci);
             System.out.println("Text Decryted : " + new String(textDecrypted));

如果是字符串,我们可以获取request.getParameter(" uname");

你能帮帮我吗?????????

加密字符串

KeyGenerator keygenerator = KeyGenerator.getInstance("DES");
        SecretKey myDesKey = keygenerator.generateKey();
        Cipher desCipher;
        desCipher = Cipher.getInstance("DES");

       desCipher.init(Cipher.ENCRYPT_MODE, myDesKey);
       byte[] text =uname.getBytes();
       byte[] textEncrypted = desCipher.doFinal(text);
       System.out.println("username Encryted : " + textEncrypted);

O / P: - [B @ 11d42b72

如何将其转换为byte []

中的servlet

1 个答案:

答案 0 :(得分:0)

是的,您将使用getParameter方法将其作为字符串。如果您想将其作为数组,则可以使用String.toCharArray()

String uname = request.getParameter("uname");
char[] unameArr = uname.toCharArray();