master_rsa_cipher_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package osscrypto
  2. import (
  3. "strings"
  4. . "gopkg.in/check.v1"
  5. )
  6. func (s *OssCryptoBucketSuite) TestMasterRsaError(c *C) {
  7. masterRsaCipher, _ := CreateMasterRsa(matDesc, RandLowStr(100), rsaPrivateKey)
  8. _, err := masterRsaCipher.Encrypt([]byte("123"))
  9. c.Assert(err, NotNil)
  10. masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, RandLowStr(100))
  11. _, err = masterRsaCipher.Decrypt([]byte("123"))
  12. c.Assert(err, NotNil)
  13. testPrivateKey := rsaPrivateKey
  14. []byte(testPrivateKey)[100] = testPrivateKey[90]
  15. masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, testPrivateKey)
  16. _, err = masterRsaCipher.Decrypt([]byte("123"))
  17. c.Assert(err, NotNil)
  18. masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, rsaPrivateKey)
  19. var cipherData CipherData
  20. err = cipherData.RandomKeyIv(aesKeySize/2, ivSize/4)
  21. c.Assert(err, NotNil)
  22. masterRsaCipher, _ = CreateMasterRsa(matDesc, rsaPublicKey, rsaPrivateKey)
  23. v := masterRsaCipher.(MasterRsaCipher)
  24. v.PublicKey = strings.Replace(rsaPublicKey, "PUBLIC KEY", "CERTIFICATE", -1)
  25. _, err = v.Encrypt([]byte("HELLOW"))
  26. c.Assert(err, NotNil)
  27. v.PrivateKey = strings.Replace(rsaPrivateKey, "PRIVATE KEY", "CERTIFICATE", -1)
  28. _, err = v.Decrypt([]byte("HELLOW"))
  29. c.Assert(err, NotNil)
  30. }