github.com/bhojpur/cache@v0.0.4/pkg/file/crypto/aes_test.go (about) 1 package crypto 2 3 // Copyright (c) 2018 Bhojpur Consulting Private Limited, India. All rights reserved. 4 5 // Permission is hereby granted, free of charge, to any person obtaining a copy 6 // of this software and associated documentation files (the "Software"), to deal 7 // in the Software without restriction, including without limitation the rights 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 // copies of the Software, and to permit persons to whom the Software is 10 // furnished to do so, subject to the following conditions: 11 12 // The above copyright notice and this permission notice shall be included in 13 // all copies or substantial portions of the Software. 14 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 // THE SOFTWARE. 22 23 import ( 24 "fmt" 25 "log" 26 ) 27 28 func ExampleAesEncrypt_Encrypt() { 29 aesEnc := AesEncrypt{"1234334"} 30 arrEncrypt, err := aesEnc.Encrypt([]byte("abcdef")) 31 if err != nil { 32 log.Println(arrEncrypt) 33 return 34 } 35 strMsg, err := aesEnc.Decrypt(arrEncrypt) 36 if err != nil { 37 log.Println(arrEncrypt) 38 return 39 } 40 fmt.Println(string(strMsg)) 41 42 // Output: abcdef 43 } 44 45 func ExampleAesEncrypt_Decrypt() { 46 aesEnc := AesEncrypt{"1234334"} 47 arrEncrypt, err := aesEnc.Encrypt([]byte("abcdef")) 48 if err != nil { 49 log.Println(arrEncrypt) 50 return 51 } 52 aesDec := AesEncrypt{"1234335"} 53 strMsg, err := aesDec.Decrypt(arrEncrypt) 54 if err != nil { 55 fmt.Printf("error password") 56 return 57 } 58 fmt.Println(string(strMsg)) 59 60 // Output: error password 61 }