jrebelprivatekey.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package main
  2. import (
  3. "crypto"
  4. "crypto/rand"
  5. "crypto/rsa"
  6. "crypto/x509"
  7. "encoding/pem"
  8. )
  9. // pem private key
  10. const privateKey = `-----BEGIN PRIVATE KEY-----
  11. MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAND3cI/pKMSd4OLMIXU/8xoEZ/nz
  12. a+g00Vy7ygyGB1Nn83qpro7tckOvUVILJoN0pKw8J3E8rtjhSyr9849qzaQKBhxFL+J5uu08QVn/
  13. tMt+Tf0cu5MSPOjT8I2+NWyBZ6H0FjOcVrEUMvHt8sqoJDrDU4pJyex2rCOlpfBeqK6XAgMBAAEC
  14. gYBM5C+8FIxWxM1CRuCs1yop0aM82vBC0mSTXdo7/3lknGSAJz2/A+o+s50Vtlqmll4drkjJJw4j
  15. acsR974OcLtXzQrZ0G1ohCM55lC3kehNEbgQdBpagOHbsFa4miKnlYys537Wp+Q61mhGM1weXzos
  16. gCH/7e/FjJ5uS6DhQc0Y+QJBAP43hlSSEo1BbuanFfp55yK2Y503ti3Rgf1SbE+JbUvIIRsvB24x
  17. Ha1/IZ+ttkAuIbOUomLN7fyyEYLWphIy9kUCQQDSbqmxZaJNRa1o4ozGRORxR2KBqVn3EVISXqNc
  18. UH3gAP52U9LcnmA3NMSZs8tzXhUhYkWQ75Q6umXvvDm4XZ0rAkBoymyWGeyJy8oyS/fUW0G63mIr
  19. oZZ4Rp+F098P3j9ueJ2k/frbImXwabJrhwjUZe/Afel+PxL2ElUDkQW+BMHdAkEAk/U7W4Aanjpf
  20. s1+Xm9DUztFicciheRa0njXspvvxhY8tXAWUPYseG7L+iRPh+Twtn0t5nm7VynVFN0shSoCIAQJA
  21. Ljo7A6bzsvfnJpV+lQiOqD/WCw3A2yPwe+1d0X/13fQkgzcbB3K0K81Euo/fkKKiBv0A7yR7wvrN
  22. jzefE9sKUw==
  23. -----END PRIVATE KEY-----`
  24. const asmPrivateKey = `
  25. -----BEGIN PRIVATE KEY-----
  26. MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAt5yrcHAAjhglnCEn
  27. 6yecMWPeUXcMyo0+itXrLlkpcKIIyqPw546bGThhlb1ppX1ySX/OUA4jSakHekNP
  28. 5eWPawIDAQABAkBbr9pUPTmpuxkcy9m5LYBrkWk02PQEOV/fyE62SEPPP+GRhv4Q
  29. Fgsu+V2GCwPQ69E3LzKHPsSNpSosIHSO4g3hAiEA54JCn41fF8GZ90b9L5dtFQB2
  30. /yIcGX4Xo7bCvl8DaPMCIQDLCUN8YiXppydqQ+uYkTQgvyq+47cW2wcGumRS46dd
  31. qQIhAKp2v5e8AMj9ROFO5B6m4SsVrIkwFICw17c0WzDRxTEBAiAYDmftk990GLcF
  32. 0zhV4lZvztasuWRXE+p4NJtwasLIyQIgVKzknJe8VOt5a3shCMOyysoNEg+YAt02
  33. O98RPCU0nJg=
  34. -----END PRIVATE KEY-----`
  35. var (
  36. privateKeyBlock, _ = pem.Decode([]byte(privateKey))
  37. asnPrivateKeyBlock, _ = pem.Decode([]byte(asmPrivateKey))
  38. )
  39. // 签名
  40. func signWithSha1(data []byte) (signature []byte, err error) {
  41. priv, err := x509.ParsePKCS8PrivateKey(privateKeyBlock.Bytes)
  42. if err != nil {
  43. return
  44. }
  45. h := crypto.Hash.New(crypto.SHA1)
  46. h.Write([]byte(data))
  47. hashed := h.Sum(nil)
  48. signature, err = rsa.SignPKCS1v15(rand.Reader, priv.(*rsa.PrivateKey), crypto.SHA1, hashed)
  49. return
  50. }
  51. //TODO fix
  52. func signWithMd5(data []byte) (signature []byte, err error) {
  53. priv, err := x509.ParsePKCS8PrivateKey(asnPrivateKeyBlock.Bytes)
  54. if err != nil {
  55. return
  56. }
  57. h := crypto.Hash.New(crypto.MD5)
  58. h.Write([]byte(data))
  59. hashed := h.Sum(nil)
  60. signature, err = rsa.SignPKCS1v15(rand.Reader, priv.(*rsa.PrivateKey), crypto.MD5, hashed)
  61. return
  62. }