@@ -18,8 +18,8 @@ openssl rsa -in private.pem -out public.pem -pubout -outform PEM
18
18
package main
19
19
20
20
import (
21
+ " fmt"
21
22
" github.com/vspaz/rsa-encrypt-decrypt-golang/pkg/cryptolib"
22
- " log"
23
23
)
24
24
25
25
const (
@@ -62,26 +62,85 @@ bQIDAQAB
62
62
-----END PUBLIC KEY-----
63
63
`
64
64
)
65
+ ```
66
+ ``` go
67
+ package main
68
+
69
+ import (
70
+ " log"
71
+ " github.com/vspaz/rsa-encrypt-decrypt-golang/pkg/cryptolib"
72
+ )
73
+
74
+ func rsaEncryptDecrypt () {
75
+ // example_1: Encrypt/Decrypt with RSA
76
+ expectedText := " some expectedText goes here"
77
+ encoder := cryptolib.NewEncoder (testPublicKey)
78
+ rsaEncryptedText := encoder.Encrypt (expectedText)
79
+
80
+ decoder := cryptolib.NewDecoder (testPrivateKey)
81
+ rsaDecryptedText := decoder.Decrypt (rsaEncryptedText)
82
+
83
+ if expectedText != rsaDecryptedText {
84
+ log.Println (" failed to decrypt" )
85
+ }
86
+ }
87
+
88
+ ```
89
+
90
+ ``` go
91
+ package main
92
+
93
+ import (
94
+ " log"
95
+ " github.com/vspaz/rsa-encrypt-decrypt-golang/pkg/cryptolib"
96
+ )
65
97
66
- func main () {
98
+ func rsaEncryptDecryptAndBase85Encode () {
67
99
text := " some text data"
68
100
69
101
// encoding example
70
102
encoder := cryptolib.NewEncoder (testPublicKey)
71
103
rsaEncodedText := encoder.Encrypt (text)
72
104
base85EncodedText := encoder.ToBase85 (rsaEncodedText)
73
- log.Printf (base85EncodedText)
105
+ log.Println (base85EncodedText)
74
106
75
107
// decoding example
76
108
decoder := cryptolib.NewDecoder (testPrivateKey)
77
109
base85decodedText := decoder.FromBase85 (base85EncodedText)
78
110
rsaDecodedText := decoder.Decrypt (base85decodedText)
79
- log.Printf (rsaDecodedText) // -> "some text data"
111
+ log.Println (rsaDecodedText) // -> "some text data"
80
112
if rsaDecodedText != text {
81
113
log.Fatal (" failed to decrypt" )
82
114
}
83
115
}
116
+ ```
117
+
118
+ ``` go
119
+ package main
120
+
121
+ import (
122
+ " github.com/vspaz/rsa-encrypt-decrypt-golang/pkg/cryptolib"
123
+ " log"
124
+ )
84
125
126
+ func rsaEncryptDecryptAndBase64Encode () {
127
+ text := " some text data"
128
+
129
+ // encoding example
130
+ encoder := cryptolib.NewEncoder (testPublicKey)
131
+ rsaEncodedText := encoder.Encrypt (text)
132
+ base64EncodedText := encoder.ToBase64 (rsaEncodedText)
133
+ log.Println (base64EncodedText)
134
+
135
+ // decoding example
136
+ decoder := cryptolib.NewDecoder (testPrivateKey)
137
+ base64decodedText := decoder.FromBase64 (base64EncodedText)
138
+ rsaDecodedText := decoder.Decrypt (base64decodedText)
139
+ log.Println (rsaDecodedText) // -> "some text data"
140
+ if rsaDecodedText != text {
141
+ log.Fatalln (" failed to decrypt" )
142
+ }
143
+ }
85
144
```
86
145
87
146
** NOTE** : please refer to [ rsa-encrypt-decrypt-python] ( https://github.com/vspaz/rsa-encrypt-decrypt-python ) if you need the Python lib.
0 commit comments