I’ve wrote a simple script to sign and verify some text and generate a
PKCS7 using OpenSSL.
require ‘openssl’
include OpenSSL
data = ‘abcdefghijklmnsopqrstuvwxyz\n’
cert = X509::Certificate.new( File::read(“my_cert.pem”) )
prv_key = PKey::RSA.new( File::read(“key_prv.pem”) )
store = X509::Store.new
store.add_cert(cert)
#gen sign
p7 = PKCS7.sign(cert,prv_key,data)
#verify sign
puts “verified: #{p7.verify([cert],store,data,0)}”
executed, the result is:
verified: true
but changing the data variable from sigle quoted to double quoted:
data = “abcdefghijklmnsopqrstuvwxyz\n”
the answer is:
verified: false
i know that escaped characters are treated diferently within double
quoted strings, but i sign and verify the same data in both cases.
¿what’s happen?
this is the content of the file ‘my_cert.pem’
-----BEGIN CERTIFICATE-----
MIIDDjCCAfYCAQEwDQYJKoZIhvcNAQEFBQAwTTELMAkGA1UEBhMCRVMxDzANBgNV
BAgMBk1hZHJpZDEtMCsGA1UEAwwkTklGIC0gMDk3NTkwMDZLIE5PTUJSRSAtIFJB
VE8gREEgTFVBMB4XDTA2MTEyOTE4MzM0M1oXDTA4MTEyOTE4MzM0M1owTTELMAkG
A1UEBhMCRVMxDzANBgNVBAgMBk1hZHJpZDEtMCsGA1UEAwwkTklGIC0gMDk3NTkw
MDZLIE5PTUJSRSAtIFJBVE8gREEgTFVBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
MIIBCgKCAQEArlOHgLZa/7xnDbRMADjv7pdSFmSxuUXjhCH9Rn6NLblRkPcxfdJh
BHleGF9cB00y1SNoN3JzxQ+Wg+lsOteRJGjXcP8weywQtCczKt2Pr9z4kPSq173Z
AyLx0pdRowqNvvDXh2HnH6MHzJVqtEOoSTKfQU7p+8c80mgkkx3U5ijctr64fY7W
bUd1zy9o1AMNLda/CudG9m8+qo6VVlGdizcNkJQGz6GW1FdAHab7xCwzqrDvdkHS
dkWou7YSLuY4t+RG6bxhDccckPhxt2ZVShwvCZIDSkOHG9Hqb8ji8UxGX+3gLTM8
pnPfiEvhw/EOtH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