sha1 question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sha1 question
# 8  
Old 03-06-2011
Quote:
Originally Posted by locoroco
These two scripts don't seem to match, so I don't know what I have done wrong.
[...]
My code is wrong, the here-string, <<< string, adds a trailing newline.

This should be OK (it still requires bash4,in order to avoid the call to another external command):

Code:
user=MyUser pass=mypass sessionid=mysessionid
_sha1=$(printf %s "${user,,}$pass"|sha1sum)
_sha1=${_sha1% *}$sessionid _sha1=$(printf %s $_sha1|sha1sum)
printf '%s\n' ${_sha1% *}

# 9  
Old 03-06-2011
This works for bash 3 and later.
Code:
#!/bin/bash

user=MyUser pass=mypass sessionid=mysessionid

user=$(echo $user | tr '[:upper:]' '[:lower:]')

_sha1=$(printf %s%s $user $pass | sha1)
_sha1=$(printf %s%s ${_sha1}${sessionid} | sha1)

printf '%s\n' ${_sha1}


Last edited by fpmurphy; 03-07-2011 at 01:22 AM.. Reason: fixed up error in code reported by Alister
# 10  
Old 03-06-2011
Hi, fpmurphy:

Quote:
Originally Posted by fpmurphy
Code:
_sha1=$(printf %s%s ${user}${pass} | tr '[:upper:]' '[:lower:]' | sha1sum)

The original php code does not modify $pass, so it should not be piped through tr.

Regards,
Alister
# 11  
Old 03-06-2011
Quote:
Originally Posted by alister
Hi, fpmurphy:
The original php code does not modify $pass, so it should not be piped through tr.
Err, does not give correct solution unless the pipe is there. And I am not modifying $pass!
# 12  
Old 03-06-2011
It works with that sample data because $pass is all lower case, but if there were an upper case character in $pass, the result would be incorrect.
This User Gave Thanks to alister For This Post:
# 13  
Old 03-07-2011
Quote:
Originally Posted by alister
It works with that sample data because $pass is all lower case, but if there were an upper case character in $pass, the result would be incorrect.
Ah, well spotted. You are correct. I will fix my example code.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. OS X (Apple)

SHA1 verification script

Hi guys! Me again! ... I'm trying to build (on MacOS directly) a bash script that will help me verify a SHA1 digest (to verify downloads and so on and so forth). So first off, here's my version of BASH under OSX: bash-4.4$ And here's my version of Sierra (macOS): 10.12.3 (16D32) ... (2 Replies)
Discussion started by: Ardzii
2 Replies

2. Programming

SHA1 hash calculation

hi i want to generate SHA1 hash of string in Linux (atmark) and downloaded the XYSSL-0.9 version code for the same.i have the algorithm which takes file as argument and returns hash of file . And of same file while I generated the key using online tools then it doesn't match with my compiled... (4 Replies)
Discussion started by: ahsaas42
4 Replies

3. UNIX Desktop Questions & Answers

Please Help me out with this question

. Make a new copy of mars.txt called marsx. What happens if you give the following commands when the files bio and marsx both already exist? Don't guess, try it! a) cp bio marsx b) mv bio marsx (2 Replies)
Discussion started by: rohit.katpalli
2 Replies

4. Shell Programming and Scripting

parse csv file, sha1 hash and output

I have a file, not really a csv, but containing delineated data just the same. Lets call that file "raw_data.txt". It contains data in the format of company name:fein number like this: first company name:123456789 second company name:987654321 what i need to do is read this file, apply... (11 Replies)
Discussion started by: FreddyG
11 Replies

5. UNIX for Dummies Questions & Answers

Question

I need to write a script file that will tell me the largest number in a group of numbers. ANy help is greatly appreciated (2 Replies)
Discussion started by: twan
2 Replies

6. UNIX for Dummies Questions & Answers

got a question

on of the question that I have is that in class . We were asked this question **What command would you use to list the last modification time of all files in /tmp whose filenames end in exactly two digits? I know that we need to to ls /tmp/ ??.... but I did not know how to find that last... (2 Replies)
Discussion started by: xzyan
2 Replies

7. UNIX for Dummies Questions & Answers

X Question

Hello, I've posted this in an X group, but I thought one of you might be able to help. I'm a novice programmer and I'm trying to write an X program in which pressing a button will launch another program. I know the syntax is something like "(Widget) -command {exec /usr/X11R6/bin/xcalc &}"... (5 Replies)
Discussion started by: af6
5 Replies

8. Shell Programming and Scripting

Question

when the user selects an option ou from the list how is it possible to let the script detect the option and carry out the appropriate action...i noe its suppose to use the for or if loop..but how ?? (3 Replies)
Discussion started by: MaRk2002
3 Replies

9. Programming

Question !

Hi a am writing a C Programe on Vi Editor (File Handelling),and i am compiling it using fcc but it not compiling ,Even Vi not saving my file.Tell me how can i do that.One More Thing I want to know that ,Is their any subsitute of conio.h. (3 Replies)
Discussion started by: at_renai2001
3 Replies
Login or Register to Ask a Question