Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var publicKey *rsa.PublicKey = (*rsa.PublicKey)(unsafe.Pointer(reflect.ValueOf(pubKey).Pointer()))
- var hashAlg crypto.Hash
- var hashLen int
- switch (signee.SignitureAlgorithm.Algorithm.String()){
- case "1.2.840.113549.1.1.4":
- if !crypto.MD5.Available() {
- fmt.Println("crypto/md5 not linked")
- panic(1)
- }
- hashAlg = crypto.MD5
- hashLen = 16
- break
- case "1.2.840.113549.1.1.5":
- if !crypto.SHA1.Available() {
- fmt.Println("crypto/sha1 not linked")
- panic(1)
- }
- hashAlg = crypto.SHA1
- hashLen = 20
- break
- case "1.2.840.113549.1.1.12":
- if !crypto.SHA384.Available() {
- fmt.Println("crypto/sha512 not linked (384)")
- panic(1)
- }
- hashAlg = crypto.SHA384
- hashLen = 48
- break
- case "1.2.840.113549.1.1.11":
- if !crypto.SHA256.Available() {
- fmt.Println("crypto/sha256 not linked")
- panic(1)
- }
- hashAlg = crypto.SHA256
- hashLen = 32
- break
- case "1.2.840.113549.1.1.13":
- if !crypto.SHA512.Available() {
- fmt.Println("crypto/sha512 not linked")
- panic(1)
- }
- hashAlg = crypto.SHA512
- hashLen = 64
- break
- default:
- println(signee.SignitureAlgorithm.Algorithm.String())
- panic(1)
- }
- pkac, err := asn1.Marshal(signee.PublicKeyAndChallenge)
- if err != nil {
- log.Fatal(err)
- }
- pkacHash := hashAlg.New().Sum(pkac)
- hash := pkacHash[len(pkacHash) - hashLen:]
- fmt.Printf("%v \t Start: %v, Len: %v, Alg: %v\n", hash, len(pkacHash)-hashLen, hashLen, hashAlg)
- err = rsa.VerifyPKCS1v15(publicKey, hashAlg, hash, signee.Signiture.Bytes)
- if err != nil {
- log.Fatal(err)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement