SO I am using the PKI R package, thanks to Simon Urbanek, and trying to understand the use of message signatures. Therefore, I can understand how to sign something.
require(PKI)
key <- PKI.genRSAkey(bits = 2048L)
priv.pem <- PKI.save.key(key)
pub.pem <- PKI.save.key(key, private=FALSE)
pub.k <- PKI.load.key(pub.pem)
x <- PKI.encrypt(charToRaw("Hello, world!"), pub.k)
rawToChar(PKI.decrypt(x, key))
x <- charToRaw("My message to sign")
sig <- PKI.sign(x, key)
PKI.verify(x, sig, key)
PKI.verify(x, sig, pub.k)
pub.pem can be written to a file as
PuK<-paste(pub.pem, collapse="")
and can be later remodeled through
pub.pem<-substring(PuK,
c(1, 27, 91, 155, 219, 283, 347, 411, 419),
c(26, 90,154,218,282,346,410,418,442))
pub.k <- PKI.load.key(pub.pem)
and then checked again as
PKI.verify(x, sig, pub.k)
However sig is raw
str(sig)
and when it is written to the file, you get
sig<-paste(sig, collapse=" " )
but you can no longer verify the signature, since it is now a string, not raw, and charToRaw does not recreate the original signature. I can get part of the path there, but not get a correctly formatted raw vector for signature verification
sigraw<-rawToChar(sig2, multiple = TRUE)
str(sapply(sigraw, FUN=charToRaw))
So, is there a way to write the signature to a file and then come back again to verify the signature?