質問編集履歴

5

block and padding

2020/02/11 01:09

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -191,3 +191,21 @@
191
191
  };
192
192
 
193
193
  ```
194
+
195
+
196
+
197
+ ## block and paddingなどについて
198
+
199
+ ```
200
+
201
+ padding : 2
202
+
203
+ unpadding : 1
204
+
205
+ blockSize : 4
206
+
207
+ mode : processBlock : 2
208
+
209
+ algorithm : keysize : 8
210
+
211
+ ```

4

optionを追加

2020/02/11 01:09

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -103,3 +103,91 @@
103
103
  ```
104
104
 
105
105
  ↑で暗号化を行っています。
106
+
107
+
108
+
109
+ ## optionの中身
110
+
111
+ ```
112
+
113
+ const option = {
114
+
115
+ format: {
116
+
117
+ stringify(cipherParams) {
118
+
119
+ // create json object with ciphertext
120
+
121
+ const jsonObj = {
122
+
123
+ ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64)
124
+
125
+ };
126
+
127
+
128
+
129
+ // optionally add iv and salt
130
+
131
+ if (cipherParams.iv) {
132
+
133
+ jsonObj.iv = cipherParams.iv.toString();
134
+
135
+ }
136
+
137
+ if (cipherParams.salt) {
138
+
139
+ jsonObj.s = cipherParams.salt.toString();
140
+
141
+ }
142
+
143
+
144
+
145
+ // stringify json object
146
+
147
+ return JSON.stringify(jsonObj);
148
+
149
+ },
150
+
151
+ parse(jsonStr) {
152
+
153
+ // parse json string
154
+
155
+ const jsonObj = JSON.parse(jsonStr);
156
+
157
+
158
+
159
+ // extract ciphertext from json object, and create cipher params object
160
+
161
+ const cipherParams = CryptoJS.lib.CipherParams.create({
162
+
163
+ ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct)
164
+
165
+ });
166
+
167
+
168
+
169
+ // optionally extract iv and salt
170
+
171
+ if (jsonObj.iv) {
172
+
173
+ cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv)
174
+
175
+ }
176
+
177
+ if (jsonObj.s) {
178
+
179
+ cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s)
180
+
181
+ }
182
+
183
+
184
+
185
+ return cipherParams;
186
+
187
+ }
188
+
189
+ }
190
+
191
+ };
192
+
193
+ ```

3

暗号化処理を追記

2020/02/11 01:01

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -45,3 +45,61 @@
45
45
  ## crypto-js
46
46
 
47
47
  [crypto-js](https://code.google.com/p/crypto-js/#The_Cipher_Output)
48
+
49
+
50
+
51
+ ## Jsで行っていること
52
+
53
+ ```
54
+
55
+ CryptoJS.AES.encrypt(plaintext, secret(), option).toString();
56
+
57
+ encrypt: function (cipher, message, key, cfg) {
58
+
59
+ // Apply config defaults
60
+
61
+ cfg = this.cfg.extend(cfg);
62
+
63
+
64
+
65
+ // Encrypt
66
+
67
+ var encryptor = cipher.createEncryptor(key, cfg);
68
+
69
+ var ciphertext = encryptor.finalize(message);
70
+
71
+
72
+
73
+ // Shortcut
74
+
75
+ var cipherCfg = encryptor.cfg;
76
+
77
+
78
+
79
+ // Create and return serializable cipher params
80
+
81
+ return CipherParams.create({
82
+
83
+ ciphertext: ciphertext,
84
+
85
+ key: key,
86
+
87
+ iv: cipherCfg.iv,
88
+
89
+ algorithm: cipher,
90
+
91
+ mode: cipherCfg.mode,
92
+
93
+ padding: cipherCfg.padding,
94
+
95
+ blockSize: cipher.blockSize,
96
+
97
+ formatter: cfg.format
98
+
99
+ });
100
+
101
+ }
102
+
103
+ ```
104
+
105
+ ↑で暗号化を行っています。

2

リンク追加

2020/02/10 09:53

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -44,4 +44,4 @@
44
44
 
45
45
  ## crypto-js
46
46
 
47
- https://code.google.com/p/crypto-js/#The_Cipher_Output
47
+ [crypto-js](https://code.google.com/p/crypto-js/#The_Cipher_Output)

1

リンク追加

2020/02/08 14:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,9 @@
39
39
  ご教授いただけますと幸いです。
40
40
 
41
41
  何卒よろしくお願いいたします。
42
+
43
+
44
+
45
+ ## crypto-js
46
+
47
+ https://code.google.com/p/crypto-js/#The_Cipher_Output