Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7718445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:10:12+00:00 2026-06-01T03:10:12+00:00

How do I convert string or a value to a byte array? I need

  • 0

How do I convert string or a value to a byte array?
I need it for SOAP authentication. My requirement is to –
On the client side, this is how to create a digest:
1. Client Side Digest Array = byte array nonce + byte array UTC date-time of UTF-8 string + byte array UTF-8 plain text password (concatenate these three).
2. Client Side SHA-1 Digest = Hash with SHA-1 algorithm the Client Side Digest Array.
3. Client Side WS-Security Digest = 64-bit encode the Client Side SHA-1 Digest

Password_Digest = Base64 ( SHA-1 ( nonce + timestamp + password ) )

This is the code I am using to generate nonce, timestamp and digest_password. User password is a string. Some ting is wrong in the whole process and my digest is not successfully generated. I guess I have these data types right, byte array and UTF8 is confusing me.
I added utf8 conversion but no difference.

def nonce
   chars = ("a".."z").to_a + ("1".."9").to_a + ("A".."Z").to_a
   @nonce = Array.new(20, '').collect{chars[rand(chars.size)]}.join
end

def timestamp
    t = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ")
    @timestamp = t.to_s
end

def digest_password

ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII')
$time =  ic.iconv( timestamp + ' ')[0..-2]
$pass =  ic.iconv( password + ' ')[0..-2]
temp = (nonce.bytes.to_a + $time.bytes.to_a + $pass.bytes.to_a)
@digest_password = Base64.strict_encode64(Digest::SHA1.hexdigest(temp.to_s))

###  temp =  Digest::SHA1.hexdigest(nonce + timestamp + password) ##old    
###@digest_password = Base64.encode64(temp) ##old

end


    <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://xml.myserver.com/ok/service/v1_5" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Header>
       <wsse:Security env:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
       <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>user</wsse:Username>
       <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">YWIwM2QyZWI3YTEwMTAzZmNkNmZiNmEwMjg1ODlkOTU0OTNmNmUxYQ==
       </wsse:Password> 
       <wsse:Nonce>ZEUyQ2J6bmw5cjdDZmt1QjVqTjQ=</wsse:Nonce>
       <wsu:Created>2012-03-27T11:08:35.125Z</wsu:Created>
</wsse:UsernameToken>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:10:14+00:00Added an answer on June 1, 2026 at 3:10 am

    Finally was able to solve this issue.

    Password_Digest = Base64 ( SHA-1 ( nonce + create + password) )
    

    nonce = nonce as string. Before Base64 endoce, E.g “1234”

    create = time as string. No encoding

    password = password as string. No encoding.

    Base64Nonce = Base64.encode64(nonce).strip #Base64 encode of “1234”

    chars = ("a".."z").to_a + ("1".."9").to_a + ("A".."Z").to_a
    nonce = Array.new(20, '').collect{chars[rand(chars.size)]}.join
    
    t = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ")
    
    $time = t
    $pass = p
    Base64Nonce = Base64.encode64(nonce).strip 
    
    $digest_pass = Base64.encode64(Digest::SHA1.digest(nonce + $time + $pass)).strip
    
    
    
              "wsse:Username" => username,
              "wsse:Password" => $digest_pass,
              "wsse:Nonce" => Base64Nonce,
              "wsu:Created" => $time,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hexidecimal string that I need to convert to a byte array.
i need to convert a base64 value into string array so simply i have
This code - Convert.ToDecimal(28.9100000000000000).ToString(c) will convert a string containing a decimal value to a
Why is there a need to convert a value (for example short) to string,
Possible Duplicate: How do you convert Byte Array to Hexadecimal String, and vice versa,
I am trying to convert a string value into a name of an attribute
In Java you can try to convert any String value to Integer, but when
Is there any java utility to convert string to hex value (integer) ?
Is there a way to convert @my_variable string into a value of @my_variable ?
How to convert hexadecimal value into emoji icons , I have a string like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.