Different Answers Decoding a Base64 String [duplicate]

Multi tool use
Multi tool use








up vote
-1
down vote

favorite
1













This question already has an answer here:



  • What's the simplest way to print a Java array?

    30 answers



  • Java: Syntax and meaning behind “[B@1ef9157”? Binary/Address?

    5 answers



I'm working to consume a web service that uses UsernameToken Profile 1.1 for authentication. Part of the process involves base64 and I'm having issues reproducing the PasswordDigest used in the web service examples:




Thus the Password_Digest of the above example used the nonce value “oWKh3qJUOqKS4JP5e1IcPg==”, the created value “2012-07-19T19:33:03.009Z” and the plain text password value “verySecret” to generate the value of “mDyN3ZYwGBSYA7nNrSVQbVqySH8=”.



Since encryption is done at the byte level; the following pseudo code represents such an operation:



BASE64_ENCODE( SHA1( BYTES_UTF( BASE64_DECODE(nonce) ) + BYTES_UTF(created) + BYTES_UTF(password) ) )




I get a different result from different Base64 Decode operations and I'm wondering why. Here's an example showing 4 different methods providing 4 different results.



public static void main(String args) 
String nonce = "oWKh3qJUOqKS4JP5e1IcPg==";
byte nonceBytes = nonce.getBytes();
byte decodedFromApache = Base64.decodeBase64(nonceBytes);
byte decodedFromJavaUtil = java.util.Base64.getDecoder().decode(nonceBytes);
java.util.Base64.Decoder decoder = java.util.Base64.getDecoder();
byte fromUtilDecoderOfBytes = decoder.decode(nonceBytes);
byte fromUtilDecoderOfString = decoder.decode(nonce);


System.out.println("From Apache: " + decodedFromApache.toString());
System.out.println("From JavaUtil: " + decodedFromJavaUtil.toString());

System.out.println("From UtilDecoder w/ byte param: " + fromUtilDecoderOfBytes);
System.out.println("From UtilDecoder w/ string param: " + fromUtilDecoderOfString);



Here is the output that I'm getting running locally:



From Apache: [B@45ee12a7 
From JavaUtil: [B@330bedb4
From UtilDecoder w/ byte param: [B@2503dbd3
From UtilDecoder w/ string param: [B@4b67cf4d


I'm ultimately going to be doing the decode in C# and get yet another result over there with illegible/invalid characters. I feel like I'm missing something fundamental in regards to string to byte conversions. Thanks.










share|improve this question















marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 0:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • From where have you taken the cited example (because I could not find it within the linked document)?
    – Markus Safar
    Nov 10 at 0:19










  • What you are getting is internal JVM representation of a byte array, not of its contents.
    – yegodm
    Nov 10 at 1:40










  • The example I cited is from the documentation on the web services I'm working to consume.
    – Casey Margell
    Nov 11 at 16:47










  • Thanks @yegodm, you're right. I'm getting the same result from each method it's just a different byte instance thus the different ToString results. /facepalm
    – Casey Margell
    Nov 11 at 17:11














up vote
-1
down vote

favorite
1













This question already has an answer here:



  • What's the simplest way to print a Java array?

    30 answers



  • Java: Syntax and meaning behind “[B@1ef9157”? Binary/Address?

    5 answers



I'm working to consume a web service that uses UsernameToken Profile 1.1 for authentication. Part of the process involves base64 and I'm having issues reproducing the PasswordDigest used in the web service examples:




Thus the Password_Digest of the above example used the nonce value “oWKh3qJUOqKS4JP5e1IcPg==”, the created value “2012-07-19T19:33:03.009Z” and the plain text password value “verySecret” to generate the value of “mDyN3ZYwGBSYA7nNrSVQbVqySH8=”.



Since encryption is done at the byte level; the following pseudo code represents such an operation:



BASE64_ENCODE( SHA1( BYTES_UTF( BASE64_DECODE(nonce) ) + BYTES_UTF(created) + BYTES_UTF(password) ) )




I get a different result from different Base64 Decode operations and I'm wondering why. Here's an example showing 4 different methods providing 4 different results.



public static void main(String args) 
String nonce = "oWKh3qJUOqKS4JP5e1IcPg==";
byte nonceBytes = nonce.getBytes();
byte decodedFromApache = Base64.decodeBase64(nonceBytes);
byte decodedFromJavaUtil = java.util.Base64.getDecoder().decode(nonceBytes);
java.util.Base64.Decoder decoder = java.util.Base64.getDecoder();
byte fromUtilDecoderOfBytes = decoder.decode(nonceBytes);
byte fromUtilDecoderOfString = decoder.decode(nonce);


System.out.println("From Apache: " + decodedFromApache.toString());
System.out.println("From JavaUtil: " + decodedFromJavaUtil.toString());

System.out.println("From UtilDecoder w/ byte param: " + fromUtilDecoderOfBytes);
System.out.println("From UtilDecoder w/ string param: " + fromUtilDecoderOfString);



Here is the output that I'm getting running locally:



From Apache: [B@45ee12a7 
From JavaUtil: [B@330bedb4
From UtilDecoder w/ byte param: [B@2503dbd3
From UtilDecoder w/ string param: [B@4b67cf4d


I'm ultimately going to be doing the decode in C# and get yet another result over there with illegible/invalid characters. I feel like I'm missing something fundamental in regards to string to byte conversions. Thanks.










share|improve this question















marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 0:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • From where have you taken the cited example (because I could not find it within the linked document)?
    – Markus Safar
    Nov 10 at 0:19










  • What you are getting is internal JVM representation of a byte array, not of its contents.
    – yegodm
    Nov 10 at 1:40










  • The example I cited is from the documentation on the web services I'm working to consume.
    – Casey Margell
    Nov 11 at 16:47










  • Thanks @yegodm, you're right. I'm getting the same result from each method it's just a different byte instance thus the different ToString results. /facepalm
    – Casey Margell
    Nov 11 at 17:11












up vote
-1
down vote

favorite
1









up vote
-1
down vote

favorite
1






1






This question already has an answer here:



  • What's the simplest way to print a Java array?

    30 answers



  • Java: Syntax and meaning behind “[B@1ef9157”? Binary/Address?

    5 answers



I'm working to consume a web service that uses UsernameToken Profile 1.1 for authentication. Part of the process involves base64 and I'm having issues reproducing the PasswordDigest used in the web service examples:




Thus the Password_Digest of the above example used the nonce value “oWKh3qJUOqKS4JP5e1IcPg==”, the created value “2012-07-19T19:33:03.009Z” and the plain text password value “verySecret” to generate the value of “mDyN3ZYwGBSYA7nNrSVQbVqySH8=”.



Since encryption is done at the byte level; the following pseudo code represents such an operation:



BASE64_ENCODE( SHA1( BYTES_UTF( BASE64_DECODE(nonce) ) + BYTES_UTF(created) + BYTES_UTF(password) ) )




I get a different result from different Base64 Decode operations and I'm wondering why. Here's an example showing 4 different methods providing 4 different results.



public static void main(String args) 
String nonce = "oWKh3qJUOqKS4JP5e1IcPg==";
byte nonceBytes = nonce.getBytes();
byte decodedFromApache = Base64.decodeBase64(nonceBytes);
byte decodedFromJavaUtil = java.util.Base64.getDecoder().decode(nonceBytes);
java.util.Base64.Decoder decoder = java.util.Base64.getDecoder();
byte fromUtilDecoderOfBytes = decoder.decode(nonceBytes);
byte fromUtilDecoderOfString = decoder.decode(nonce);


System.out.println("From Apache: " + decodedFromApache.toString());
System.out.println("From JavaUtil: " + decodedFromJavaUtil.toString());

System.out.println("From UtilDecoder w/ byte param: " + fromUtilDecoderOfBytes);
System.out.println("From UtilDecoder w/ string param: " + fromUtilDecoderOfString);



Here is the output that I'm getting running locally:



From Apache: [B@45ee12a7 
From JavaUtil: [B@330bedb4
From UtilDecoder w/ byte param: [B@2503dbd3
From UtilDecoder w/ string param: [B@4b67cf4d


I'm ultimately going to be doing the decode in C# and get yet another result over there with illegible/invalid characters. I feel like I'm missing something fundamental in regards to string to byte conversions. Thanks.










share|improve this question
















This question already has an answer here:



  • What's the simplest way to print a Java array?

    30 answers



  • Java: Syntax and meaning behind “[B@1ef9157”? Binary/Address?

    5 answers



I'm working to consume a web service that uses UsernameToken Profile 1.1 for authentication. Part of the process involves base64 and I'm having issues reproducing the PasswordDigest used in the web service examples:




Thus the Password_Digest of the above example used the nonce value “oWKh3qJUOqKS4JP5e1IcPg==”, the created value “2012-07-19T19:33:03.009Z” and the plain text password value “verySecret” to generate the value of “mDyN3ZYwGBSYA7nNrSVQbVqySH8=”.



Since encryption is done at the byte level; the following pseudo code represents such an operation:



BASE64_ENCODE( SHA1( BYTES_UTF( BASE64_DECODE(nonce) ) + BYTES_UTF(created) + BYTES_UTF(password) ) )




I get a different result from different Base64 Decode operations and I'm wondering why. Here's an example showing 4 different methods providing 4 different results.



public static void main(String args) 
String nonce = "oWKh3qJUOqKS4JP5e1IcPg==";
byte nonceBytes = nonce.getBytes();
byte decodedFromApache = Base64.decodeBase64(nonceBytes);
byte decodedFromJavaUtil = java.util.Base64.getDecoder().decode(nonceBytes);
java.util.Base64.Decoder decoder = java.util.Base64.getDecoder();
byte fromUtilDecoderOfBytes = decoder.decode(nonceBytes);
byte fromUtilDecoderOfString = decoder.decode(nonce);


System.out.println("From Apache: " + decodedFromApache.toString());
System.out.println("From JavaUtil: " + decodedFromJavaUtil.toString());

System.out.println("From UtilDecoder w/ byte param: " + fromUtilDecoderOfBytes);
System.out.println("From UtilDecoder w/ string param: " + fromUtilDecoderOfString);



Here is the output that I'm getting running locally:



From Apache: [B@45ee12a7 
From JavaUtil: [B@330bedb4
From UtilDecoder w/ byte param: [B@2503dbd3
From UtilDecoder w/ string param: [B@4b67cf4d


I'm ultimately going to be doing the decode in C# and get yet another result over there with illegible/invalid characters. I feel like I'm missing something fundamental in regards to string to byte conversions. Thanks.





This question already has an answer here:



  • What's the simplest way to print a Java array?

    30 answers



  • Java: Syntax and meaning behind “[B@1ef9157”? Binary/Address?

    5 answers







java c# base64 sha1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 23:54

























asked Nov 9 at 23:45









Casey Margell

162112




162112




marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 0:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Andreas java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 0:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • From where have you taken the cited example (because I could not find it within the linked document)?
    – Markus Safar
    Nov 10 at 0:19










  • What you are getting is internal JVM representation of a byte array, not of its contents.
    – yegodm
    Nov 10 at 1:40










  • The example I cited is from the documentation on the web services I'm working to consume.
    – Casey Margell
    Nov 11 at 16:47










  • Thanks @yegodm, you're right. I'm getting the same result from each method it's just a different byte instance thus the different ToString results. /facepalm
    – Casey Margell
    Nov 11 at 17:11
















  • From where have you taken the cited example (because I could not find it within the linked document)?
    – Markus Safar
    Nov 10 at 0:19










  • What you are getting is internal JVM representation of a byte array, not of its contents.
    – yegodm
    Nov 10 at 1:40










  • The example I cited is from the documentation on the web services I'm working to consume.
    – Casey Margell
    Nov 11 at 16:47










  • Thanks @yegodm, you're right. I'm getting the same result from each method it's just a different byte instance thus the different ToString results. /facepalm
    – Casey Margell
    Nov 11 at 17:11















From where have you taken the cited example (because I could not find it within the linked document)?
– Markus Safar
Nov 10 at 0:19




From where have you taken the cited example (because I could not find it within the linked document)?
– Markus Safar
Nov 10 at 0:19












What you are getting is internal JVM representation of a byte array, not of its contents.
– yegodm
Nov 10 at 1:40




What you are getting is internal JVM representation of a byte array, not of its contents.
– yegodm
Nov 10 at 1:40












The example I cited is from the documentation on the web services I'm working to consume.
– Casey Margell
Nov 11 at 16:47




The example I cited is from the documentation on the web services I'm working to consume.
– Casey Margell
Nov 11 at 16:47












Thanks @yegodm, you're right. I'm getting the same result from each method it's just a different byte instance thus the different ToString results. /facepalm
– Casey Margell
Nov 11 at 17:11




Thanks @yegodm, you're right. I'm getting the same result from each method it's just a different byte instance thus the different ToString results. /facepalm
– Casey Margell
Nov 11 at 17:11

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

sY643Im6PDD7 fd2R JsqvY5,l QLJKjSZd58S,qLdasnx3l18oWV Q qIVyzSveQHT
NGzFrh 9GZ3vP Imo Q0eSdLwl3W,Dr5xITOMiWA

Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Ruanda

Ondo