digest

Converting a byte [] to PrivateKey in java for digital signature

两盒软妹~` 提交于 2019-12-03 21:43:59
I need to digitally sign a String using the SHA-1 digest algorithm first and then apply the RSA algorithm, using a PrivateKey to sign it. I already have the PrivateKey stored in my database as data type char(250) in base64. My problem is that I don't know how to convert it into a PrivateKey for using it for signing in: Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, privateKey); byte[] cipherText = cipher.doFinal(digest); Digest was an array of bytes to which I applied the SHA-1 digest algorithm: MessageDigest md = MessageDigest.getInstance("SHA-1"); byte [] ba =

Java MessageDigest doesn't work

假如想象 提交于 2019-12-03 21:05:52
I can't make MessageDigest work, the program gives me two error: UnsupportedEncodingException, NoSuchAlgorithmException byte[] bytesOfchat_key = "lol".getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] Digest = md.digest(bytesOfchat_key); If I throw the errors, it give me ワ￟ᄡ9ᅦヌnp>0xd￉z as response ( 16 chars ) PS: I have used to print the Digest for (byte b : Digest) { System.out.print((char)b); } md5 returns hexadecimal numbers, so for decoding it to a String you could use String plaintext = "lol"; MessageDigest m = MessageDigest.getInstance("MD5"); m.reset(); m

How to use common crypto and/or calculate sha256 in swift 2 & 3

梦想的初衷 提交于 2019-12-03 16:36:59
问题 I am trying to make hash a password value according to sha256. I already search this but there is no info about swift 2. This solution did not worked for me func sha256(data:String) -> String { let data = self.dataUsingEncoding(NSUTF8StringEncoding)! var digest = [UInt8](count:Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0) CC_SHA256(data.bytes, CC_LONG(data.length), &digest) let hexBytes = digest.map { String(format: "%02hhx", $0) } return hexBytes.joinWithSeparator("") } It gives error: Use

Why would HMAC SHA-1 return a different digest with the same input?

陌路散爱 提交于 2019-12-03 16:03:53
I am trying to build a working encrypted signature for the Amazon S3 web service, writing a connection library using Objective C. I have run into HMAC SHA-1 digest problems with the ObjC code, so I'm putting that to the side and looking at existing, working Perl code, to try to troubleshoot digest creation. I am testing HMAC SHA-1 digest output from the s3ls command of the Net::Amazon::S3 package and comparing that against the _encode subroutine that I pulled out and put into its own perl script: #!/usr/bin/perl -w use MIME::Base64 qw(encode_base64); use Digest::HMAC_SHA1; use String::Escape

AngularJS: Fire an event immediately after $scope.$digest

梦想的初衷 提交于 2019-12-03 08:56:34
问题 In my AngularJS app, there's several points at which I want to wait for a $scope to be processed into the DOM, and then run some code on it, like a jquery fadeIn, for example. Is there a way to listen for a digestComplete message of some sort? My current method is, immediately after setting whatever $scope variables I want rendered, use setTimeout with a delay of 0 ms, so that it will let the scope finish digesting, and then run the code, which works perfectly. Only problem is, I very

Creating an md5 hash of a number, string, array, or hash in Ruby

柔情痞子 提交于 2019-12-03 06:30:05
问题 I need to create a signature string for a variable in Ruby, where the variable can be a number, a string, a hash, or an array. The hash values and array elements can also be any of these types. This string will be used to compare the values in a database (Mongo, in this case). My first thought was to create an MD5 hash of a JSON encoded value, like so: (body is the variable referred to above) def createsig(body) Digest::MD5.hexdigest(JSON.generate(body)) end This nearly works, but JSON

How to use common crypto and/or calculate sha256 in swift 2 & 3

被刻印的时光 ゝ 提交于 2019-12-03 05:47:14
I am trying to make hash a password value according to sha256. I already search this but there is no info about swift 2. This solution did not worked for me func sha256(data:String) -> String { let data = self.dataUsingEncoding(NSUTF8StringEncoding)! var digest = [UInt8](count:Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0) CC_SHA256(data.bytes, CC_LONG(data.length), &digest) let hexBytes = digest.map { String(format: "%02hhx", $0) } return hexBytes.joinWithSeparator("") } It gives error: Use of unresolved identifier CC_SHA256_DIGEST_LENGTH Add a bridging header and add the import to it:

Example of SOAP request authenticated with WS-UsernameToken

吃可爱长大的小学妹 提交于 2019-12-03 03:15:42
问题 I'm trying to authenticate a SOAP request using WS-UsernameToken spec, but the target device is always denying access. My non-working request looks like this. (The password I'm trying to hash is system .) <?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns="http://www.w3.org/2003/05/soap-envelope"> <Header> <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <UsernameToken> <Username>root</Username> <Password Type="http://docs.oasis-open.org

Different results with Java's digest versus external utilities

百般思念 提交于 2019-12-03 02:08:00
问题 I have written a simple Java class to generate the hash values of the Windows Calculator file. I am using Windows 7 Professional with SP1 . I have tried Java 6.0.29 and Java 7.0.03 . Can someone tell me why I am getting different hash values from Java versus (many!) external utilities and/or websites? Everything external matches with each other, only Java is returning different results. import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io

HTTP Digest Authentication

假如想象 提交于 2019-12-03 02:01:52
I want to use HTTP Digest Authentication with a central database that stores usernames and encrypted passwords. These data should be used by different servers like Apache httpd or Tomcat for example. The clients will be humans with browsers and other applications communicating in a RESTful way. As far as I understand I could not use a table with hashed passwords. It is only possibly to store HA1 = MD5(username:realm:password) where a clear text password is required - correct? On the other hand it seems to be possible to use hashed passwords with Apache httpd: Apache httpd doc says: The first