-
-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Hi mas @gettalong
I will implement hash signing with another service. The codes like below (the gist is attached)
https://gist.github.com/heruwaspodov/ecdb35c19e57abb97894389a1bde4707#file-annotation_signature_hash-rb
def signing_mechanism
@signing_mechanism ||= lambda do |digest, hash|
payload = {
digest: digest,
hash: AesCipher.new.encrypt(hash)
}.to_json
# Golang Services
# response = RestClient.post('http://127.0.0.1:7777/hash_signing', payload,
# content_type: :json)
# Ruby Services
response = RestClient.post('http://127.0.0.1:3000/api/v1/hash_signing', payload,
content_type: :json)
signed_hash = JSON.parse(response.body)['data']['signed_hash']
signature = AesCipher.new.decrypt(signed_hash)
binary_signature = signature.force_encoding('ASCII-8BIT')
puts "Final signature class: #{binary_signature.class}"
puts "Final signature encoding: #{binary_signature.encoding}"
puts "Final signature length: #{binary_signature.bytesize}"
if verify_signature(hash, binary_signature)
puts 'Signature verified successfully!'
else
puts 'WARNING: Signature verification failed!'
end
binary_signature
end
end
I already created the Golang service to sign the hash using private_key (I use the Hexapdf private key). The gist is -> https://gist.github.com/heruwaspodov/ecdb35c19e57abb97894389a1bde4707#file-go_hash_signing_service-go
response = RestClient.post('http://127.0.0.1:3000/api/v1/hash_signing', payload, content_type: :json)
but the result is always an invalid signature, like the picture below. Meanwhile, the verified signature is true (show the -> puts 'Signature verified successfully!').
I already checked the encryption between Ruby and Golang. It works to encrypt with Golang and decrypt with Ruby and vice versa.
https://onecompiler.com/go/437uxvhrm
https://onecompiler.com/ruby/437uxu6q3
the binary is not changed and always same identic.
The strange thing, is if I hit another service that was created with ruby (https://gist.github.com/heruwaspodov/ecdb35c19e57abb97894389a1bde4707#file-ruby_hash_signing_service-rb)
response = RestClient.post('http://127.0.0.1:3000/api/v1/hash_signing', payload, content_type: :json)
Showing a message : WARNING: Signature verification failed!, but the certificate is safe.
could you give me advice mas. @gettalong? :') I am already stuck in this
thank you