is there a way to convert sha-1 to sha256 for a file. suppose SHA-1 of a files is a14bab81de06e9b590f6cfcd400f90fb5b667eff
Func(a14bab81de06e9b590f6cfcd400f90fb5b667eff) = SHA-256
Here I don't have the original file, else Get-FileHash in powershell would have solved my problem. Thank you.
No, that's not possible. SHA algorithms need to see all the data in the original files.
Related
Hi I'm looking for an example on how to use the CME Simple Binary Encoding. Is it as simple as generating decoders using the SBETool?
Yes it is. SBE defines the wire format. SBETool will generate codecs to encode/decode to this format.
There are examples in the github repository:
https://github.com/real-logic/simple-binary-encoding/tree/master/examples
I am trying to parse a CSV file generated from an Excel spreadsheet.
Here is my code
require 'csv'
file = File.open("input_file")
csv = CSV.parse(file)
But I get this error
ArgumentError: invalid byte sequence in UTF-8
I think the error is because Excel encodes the file into ISO 8859-1 (Latin-1) and not in UTF-8
Can someone help me with a workaround for this issue, please
Thanks in advance.
You need to tell Ruby that the file is in ISO-8859-1. Change your file open line to this:
file=File.open("input_file", "r:ISO-8859-1")
The second argument tells Ruby to open read only with the encoding ISO-8859-1.
Specify the encoding with encoding option:
CSV.foreach(file.path, headers: true, encoding:'iso-8859-1:utf-8') do |row|
...
end
You can supply source encoding straight in the file mode parameter:
CSV.foreach( "file.csv", "r:windows-1250" ) do |row|
<your code>
end
If you have only one (or few) file, so when its not needed to automatically declare encoding on whatever file you get from input, and you have the contents of this file visible in plaintext (txt, csv etc) separated with i.e. semicolon, you can create new file with .csv extension manually, and paste the contents of your file there, then parse the contents like usual.
Keep in mind, that this is a workaround, but in need of parsing in linux only one big excel file, converted to some flavour of csv, it spares time on experimenting with all those fancy encodings
Save the file in utf-8, unless for some reason you need to save it differently in which case you may specify the encoded set while reading the file
add second argument "r:ISO-8859-1" as File.open("input_file","r:ISO-8859-1" )
I had this same problem and was just using google spreadsheets and then downloading as a CSV. That was the easiest solution.
Then I came across this gem
https://github.com/singlebrook/utf8-cleaner
Now I don't need to worry about this issue at all. Hope this helps!
In a particular Rails application, I'm pulling binary data out of LDAP into a variable for processing. Is there a way to check if the variable contains binary data? I don't want to continue with processing of this variable if it's not binary. I would expect to use is_a?...
In fact, the binary data I'm pulling from LDAP is a photo. So maybe there's an even better way to ensure the variable contains binary JPEG data? The result of this check will determine whether to continue processing the JPEG data, or to render a default JPEG from disk instead.
There is actually a lot more to this question than you might think. Only since Ruby 1.9 has there been a concept of characters (in some encoding) versus raw bytes. So in Ruby 1.9 you might be able to get away with requesting the encoding. Since you are getting stuff from LDAP the encoding for the strings coming in should be well known, most likely ISO-8859-1 or UTF-8.
In which case you can get the encoding and act on that:
some_variable.encoding # => when ASCII-8BIT, treat as a photo
Since you really want to verify that the binary data is a photo, it would make sense to run it through an image library. RMagick comes to mind. The documentation will show you how to verify that any binary data is actually JPEG encoded. You will then also be able to store other properties such as width and height.
If you don't have RMagick installed, an alternative approach would be to save the data into a Tempfile, drop down into Unix (assuming you are on Unix) and try to identify the file. If your system has ImageMagick installed, the identify command will tell you all about images. But just calling file on it will tell you this too:
~/Pictures$ file P1020359.jpg
P1020359.jpg: JPEG image data, EXIF standard, comment: "AppleMark"
You need to call the identify and file commands in a shell from Ruby:
%x(identify #{tempfile})
%x(file #{tempfile})
My current Ivy configuration fails to resolve because of this error:
problem while downloading module descriptor:
http://repo1.maven.org/maven2/commons-fileupload/commons-fileupload/1.2.2/commons-fileupload-1.2.2.pom:
invalid sha1:
expected=ad3fda4adc95eb0d061341228cc94845ddb9a6fe
computed=0ce5d4a03b07c8b00ab60252e5cacdc708a4e6d8
How can I disable (or work around) Ivy's check of the SHA1 checksum?
I think you could tell your resolver to ignore checksums by setting the property to an empty String.
http://ant.apache.org/ivy/history/latest-milestone/settings/resolvers.html
Or you could define it globally by setting the attribute ivy.checksums to "":
From the Documentation (http://ant.apache.org/ivy/history/latest-milestone/concept.html#checksum):
For the moment Ivy supports the md5
and sha1 algorithms.
The configuration of using md5 and/or
sha1 can be done globally or by
dependency resolver. Globally, use the
ivy.checksums variable to list the
check to be done (only md5 and sha1
are supported). On each resolver you
can use the checksums attribute to
override the global setting.
The setting is a comma separated list
of checksum algorithms to use. During
checking (at download time), the first
checksum found is checked, and that's
all. This means that if you have a
"sha1, md5" setting, then if ivy finds
a sha1 file, it will compare the
downloaded file sha1 against this
sha1, and if the comparison is ok, it
will assume the file is ok. If no sha1
file is found, it will look for an md5
file. If none is found no checking is
done. During publish, all listed
checksum algorithms are computed and
uploaded.
By default checksum algorithms are
"sha1, md5".
If you want to change this default,
you can set the variable
ivy.checksums. Hence, to disable
checksum validation you just have to
set ivy.checksums to "".
I just found this about the checksum issue:
Corrupt checksum in Maven Central
how to read data from .dat files ?
i just tried like this memo1.lines.loadfromfile('c:\myfile.dat'); but not worked
Note : File type is binary
can any one please help me :)
#radick to show the contents of an binary file in a memo control you must encode o convert the data to valid ASCII characters, to turn it all into text. because you can not load something that is not text into a text control.
you can find a very nice sample from Peter Below in this link.
read a binary file and display the byte values as ASCII?
(source: swissdelphicenter.ch)
Use the TStream descendants from the VCL Classes unit to read binary files.
There are plenty Delphi TStream reading binary files examples you can find using Google.
--jeroen
You might look at this post as they seem to be discussing this very thing.