OSDN Git Service

Create ossClient.go (#574)
[bytom/vapor.git] / vendor / github.com / aliyun / aliyun-oss-go-sdk / oss / crypto / master_rsa_cipher_test.go
1 package osscrypto
2
3 import (
4         "strings"
5
6         . "gopkg.in/check.v1"
7 )
8
9 func (s *OssCryptoBucketSuite) TestMasterRsaError(c *C) {
10
11         masterRsaCipher, _ := CreateMasterRsa(matDesc, RandLowStr(100), rsaPrivateKey)
12         _, err := masterRsaCipher.Encrypt([]byte("123"))
13         c.Assert(err, NotNil)
14
15         masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, RandLowStr(100))
16         _, err = masterRsaCipher.Decrypt([]byte("123"))
17         c.Assert(err, NotNil)
18
19         testPrivateKey := rsaPrivateKey
20         []byte(testPrivateKey)[100] = testPrivateKey[90]
21         masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, testPrivateKey)
22         _, err = masterRsaCipher.Decrypt([]byte("123"))
23         c.Assert(err, NotNil)
24
25         masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, rsaPrivateKey)
26
27         var cipherData CipherData
28         err = cipherData.RandomKeyIv(aesKeySize/2, ivSize/4)
29         c.Assert(err, NotNil)
30
31         masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, rsaPrivateKey)
32         v := masterRsaCipher.(MasterRsaCipher)
33
34         v.PublicKey = strings.Replace(rsaPublicKey, "PUBLIC KEY", "CERTIFICATE", -1)
35         _, err = v.Encrypt([]byte("HELLOW"))
36         c.Assert(err, NotNil)
37
38         v.PrivateKey = strings.Replace(rsaPrivateKey, "PRIVATE KEY", "CERTIFICATE", -1)
39         _, err = v.Decrypt([]byte("HELLOW"))
40         c.Assert(err, NotNil)
41 }