drvkf88226 2013-05-28 01:46
浏览 26

如何根据webserver中的php部分在android java中执行WSSE身份验证?

I use symfony2 for web server and use wsse authentication with x-wsse header.

The question actually is about which exact functions I should use in Java to give the same result as in PHP.

PHP part for header generation:

$nonce = substr( md5( uniqid( 'nonce_', true ) ), 0, 16 );
$nonceHigh = base64_encode( $nonce );
$passwordDigest = base64_encode( sha1( $nonce . $created . $password . "{" . $user->getSalt() . "}", true ) );
$header = "UsernameToken Username=\"{$username}\", PasswordDigest=\"{$passwordDigest}\", Nonce=\"{$nonceHigh}\", Created=\"{$created}\"";

PHP part for header verify:

$expected = base64_encode( sha1( base64_decode( $nonce ) . $created . $secret, true ) );

I don't know why it uses nonceHigh instead of nonce directly? I believe this cause the problem in java. And I also don't know should generate nonce or use the one generate from server. In order to do the compare, I reused the nonce from server to generate digest.

byte [] nonceLow = Base64.decode(nonceHigh, Base64.DEFAULT); // nonceHigh is from above
String nonce = String.valueOf(nonceLow); // this give strange result. is it wrong?
String temp = nonce + format(now) + password;
try {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    //new String(Base64.encodeBase64(md.digest(temp.getBytes())));
    digest = Base64.encodeToString(md.digest(temp.getBytes("UTF-8")), Base64.DEFAULT);
} catch (Exception e) {
    throw new AuthenticationException(e.getMessage(), e);
}

String wsse =
    "UsernameToken Username=\"" + username
        + "\", "
        + "PasswordDigest=\""
        + digest
        + "\", "
        + "Nonce=\""
        + nonceHIGH
        + "\", "
        + "Created=\""
        + format(now)
        + "\"";

Question is:

  1. Why PHP uses nonceHight instead of nonce?
  2. android java Base64.encodeToString() == php base64_encode()?
  3. android java Base64.decode() == php base64_decode()?
  • 写回答

1条回答 默认 最新

  • duandan9680 2013-05-28 15:26
    关注

    Nobody answer. Ok, I put my found here in case somebody meet the same issue. This solve the problem.

    Base64.encodeToString(temp.getBytes("ISO-8859-1"), Base64.NO_WRAP);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据