github.com/emmansun/gmsm@v0.29.1/pkcs8/pkcs8_norace_test.go (about)

     1  package pkcs8_test
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  // From https://tools.ietf.org/html/rfc7914
     8  const encryptedRFCscrypt = `-----BEGIN ENCRYPTED PRIVATE KEY-----
     9  MIHiME0GCSqGSIb3DQEFDTBAMB8GCSsGAQQB2kcECzASBAVNb3VzZQIDEAAAAgEI
    10  AgEBMB0GCWCGSAFlAwQBKgQQyYmguHMsOwzGMPoyObk/JgSBkJb47EWd5iAqJlyy
    11  +ni5ftd6gZgOPaLQClL7mEZc2KQay0VhjZm/7MbBUNbqOAXNM6OGebXxVp6sHUAL
    12  iBGY/Dls7B1TsWeGObE0sS1MXEpuREuloZjcsNVcNXWPlLdZtkSH6uwWzR0PyG/Z
    13  +ZXfNodZtd/voKlvLOw5B3opGIFaLkbtLZQwMiGtl42AS89lZg==
    14  -----END ENCRYPTED PRIVATE KEY-----
    15  `
    16  
    17  func TestParseFFCscryptPrivateKey(t *testing.T) {
    18  	keyList := []testPrivateKey{
    19  		{
    20  			name:      "encryptedRFCscrypt",
    21  			clear:     "",
    22  			encrypted: encryptedRFCscrypt,
    23  			password:  "Rabbit",
    24  		},
    25  	}
    26  	for i, key := range keyList {
    27  		t.Run(key.name, func(t *testing.T) {
    28  			testParsePKCS8PrivateKey(t, i, &key)
    29  		})
    30  	}
    31  }
    32  
    33  const encryptedSM9SignMasterPrivateKey = `-----BEGIN ENCRYPTED SM9 SIGN MASTER KEY-----
    34  MIIBNjBhBgkqhkiG9w0BBQ0wVDA0BgkqhkiG9w0BBQwwJwQQuRb0v3wC0mAANvym
    35  YLiNSAIDAQAAAgEQMAsGCSqBHM9VAYMRAjAcBggqgRzPVQFoAgQQuzlPtraTjW+9
    36  EpGFcss7TgSB0KnwoVMBPUFcZEqiH1DPFZVqHcbdfmZheeIXCdeS5cYGL7Cg6Ohd
    37  YZe9LWCFNBAvJz6zxeJGiaeR3VW5QDB+jPtSYIu9ET85yFsaohLt/ZNdgdGec2s6
    38  rmG5/ufL+9LtprtWF4BcbwTCCPr6mX3Tvq+Xacw0YY9VHcpUDOUHGwkdhea82M5D
    39  nUCi5FhiNKDe4Qfp7HG597FlK9Vwy5Nn5xRKsfoG2JJuQYZkqmORFJA/aQQq/ejD
    40  NbR0XajuWC9+bMq3SeEyT6Je0aEeHuOfKFw=
    41  -----END ENCRYPTED SM9 SIGN MASTER KEY-----
    42  `
    43  
    44  const encryptedSM9SignPrivateKey = `-----BEGIN ENCRYPTED SM9 SIGN PRIVATE KEY-----
    45  MIIBVjBhBgkqhkiG9w0BBQ0wVDA0BgkqhkiG9w0BBQwwJwQQxWctHikJLVP2A7fQ
    46  nm6qwQIDAQAAAgEQMAsGCSqBHM9VAYMRAjAcBggqgRzPVQFoAgQQfuWLjhO7iJNX
    47  2owsXE8/6gSB8Ot4oMs97o7dDd6o2U29uTjvkt7Xq/ti/2OPoOvDeGr/SWTmLUHY
    48  6X71SpB/GAmBVE1qMXSxFHotgeq1cbwuZtwqLV2GA0etAnC2MZV/2BYcx+qOwwgX
    49  uljiXhlvpvxHfxxdL7HzJ5oC+AuMblQZnAvaicmS9Pr+EPk4gzusiCc4cu1q+sTh
    50  xl4HzCz08DYx8l5j1B/FCnN0/9tv2F2Q6j3xWARFC8EJPAEhALdO+hol56Tz7A2a
    51  zSK4N8ox4ip3G8L6TVMIlc8qFIfsnaVn+dQSWDubya8Lq4AieEs8mL+kPqEnSIUX
    52  fYuup/MCEz2zpA==
    53  -----END ENCRYPTED SM9 SIGN PRIVATE KEY-----
    54  `
    55  
    56  const encryptedSM9EncMasterPrivateKey = `-----BEGIN ENCRYPTED SM9 ENC MASTER KEY-----
    57  MIH2MGEGCSqGSIb3DQEFDTBUMDQGCSqGSIb3DQEFDDAnBBAjXv966WmKuBfUH1Bq
    58  OMwUAgMBAAACARAwCwYJKoEcz1UBgxECMBwGCCqBHM9VAWgCBBAtVvud0awyXO1r
    59  dz92Pn+9BIGQlAsGegoSrApDm+rbszu1wsUwAVbq+EtgkraBSZRqGYByBOSN9G9m
    60  p0lZJ75/TJMqRunkUhAUorNzXkdy2nab1VRs+Y8lKzhw5Y7KLnjbRsoDEPcvluSW
    61  UVHgVDiaGKLKlKWTdhRRzLnBOocE0LA3FnOH86eUFjGY87ss6vz8iD9JHHfap4yr
    62  Yut8eao1nBSY
    63  -----END ENCRYPTED SM9 ENC MASTER KEY-----
    64  `
    65  
    66  const encryptedSM9EncPrivateKey = `
    67  -----BEGIN ENCRYPTED SM9 ENC PRIVATE KEY-----
    68  MIIBVjBhBgkqhkiG9w0BBQ0wVDA0BgkqhkiG9w0BBQwwJwQQ7qFYth3lhEj9pHl4
    69  V0HeiwIDAQAAAgEQMAsGCSqBHM9VAYMRAjAcBggqgRzPVQFoAgQQvk8cAqLQcGr1
    70  LfRo8lz6TwSB8Ma6HVx/t1q+wbu+NLLzq1uok7zNBKM8Z9hFiqrY1pngZTtweVHP
    71  w/r6inOU4rI9Eex6R7C4koT9cGYN4QBur3BHxTLPM7C4knldxxYHuA98MEGHMMcE
    72  gJIcgZlrkdprvLSXqdKJ/Ee7Ut4SuJuMW/Ww0hTrOmnI0j4cRAaZAgEh9Lh9B5CK
    73  tzO+xTcb9siTzgRDKxnsZB85c1pwzQ3LH1KNR7tsg1z/AW+Hab4+8WX7mIIlvmVM
    74  zkRVx8ZgZCNo/MTFjw2qCNVsGrcj/xFm63p8eWoYGx6eXS6nr3IYRIDwR5F7CoNY
    75  h1/9v+oJWBaPxQ==
    76  -----END ENCRYPTED SM9 ENC PRIVATE KEY-----
    77  `
    78  
    79  func TestParseSM9PrivateKey(t *testing.T) {
    80  	keyList := []testPrivateKey{
    81  		{
    82  			name:      "encryptedSM9SignMasterPrivateKey",
    83  			clear:     "",
    84  			encrypted: encryptedSM9SignMasterPrivateKey,
    85  			password:  "123456",
    86  		},
    87  		{
    88  			name:      "encryptedSM9SignPrivateKey",
    89  			clear:     "",
    90  			encrypted: encryptedSM9SignPrivateKey,
    91  			password:  "123456",
    92  		},
    93  		{
    94  			name:      "encryptedSM9EncMasterPrivateKey",
    95  			clear:     "",
    96  			encrypted: encryptedSM9EncMasterPrivateKey,
    97  			password:  "123456",
    98  		},
    99  		{
   100  			name:      "encryptedSM9EncPrivateKey",
   101  			clear:     "",
   102  			encrypted: encryptedSM9EncPrivateKey,
   103  			password:  "123456",
   104  		},
   105  	}
   106  	for i, key := range keyList {
   107  		t.Run(key.name, func(t *testing.T) {
   108  			testParsePKCS8PrivateKey(t, i, &key)
   109  		})
   110  	}
   111  }