質問編集履歴

2

暗号化ではなく、復号する際に嵌っています。

2019/05/08 09:41

投稿

hirosnow
hirosnow

スコア16

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  初めまして。
2
2
 
3
- で嵌っているので、お助けいただけますと嬉しいです。
3
+ 号で嵌っているので、お助けいただけますと嬉しいです。
4
4
 
5
5
 
6
6
 

1

暗号文をbinaryに変更しました。

2019/05/08 09:41

投稿

hirosnow
hirosnow

スコア16

test CHANGED
@@ -1 +1 @@
1
- PHP,JS(Node.js)での暗号化,復号につ
1
+ PHPで暗号化,JS(Node.js)で復号ができな
test CHANGED
@@ -14,9 +14,19 @@
14
14
 
15
15
  ### 発生している問題・エラーメッセージ
16
16
 
17
+ ###### 修正前
18
+
17
19
  ```
18
20
 
19
21
  (node:11944) UnhandledPromiseRejectionWarning: Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
22
+
23
+ ```
24
+
25
+ ###### 修正後
26
+
27
+ ```
28
+
29
+ (node:18364) UnhandledPromiseRejectionWarning: Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
20
30
 
21
31
  ```
22
32
 
@@ -27,6 +37,8 @@
27
37
  平文:テスト太郎
28
38
 
29
39
 
40
+
41
+ ###### 修正前
30
42
 
31
43
  ```PHP
32
44
 
@@ -74,6 +86,54 @@
74
86
 
75
87
 
76
88
 
89
+ ###### 修正後
90
+
91
+ ```PHP
92
+
93
+ openssl_encrypt($planeText, 'aes-256-ecb', 'testtes', 1);
94
+
95
+ ```
96
+
97
+
98
+
99
+ ```Node
100
+
101
+ const crypto = require("crypto");
102
+
103
+
104
+
105
+ const planeText = 'A4A74C2C8DB1D3E108D5C1A40950CC5B';//平文をPHPで暗号化した文字列
106
+
107
+ const buffer = new Buffer(planeText, 'base64');
108
+
109
+ const ascii = buffer.toString('ascii');
110
+
111
+ console.log('ascii: '+ ascii);
112
+
113
+
114
+
115
+ const passowrd = 'testtes';
116
+
117
+ const alg = 'aes-256-ecb'
118
+
119
+ const encoding = 'binary'
120
+
121
+
122
+
123
+ const decipher = crypto.createDecipher(alg, passowrd);
124
+
125
+ let dec = decipher.update(ascii, encoding, 'utf8');
126
+
127
+ dec += decipher.final('utf8');
128
+
129
+
130
+
131
+ console.log('decrypted: ' + dec);
132
+
133
+ ```
134
+
135
+
136
+
77
137
  ### 試したこと
78
138
 
79
139
 
@@ -92,6 +152,10 @@
92
152
 
93
153
 
94
154
 
155
+ また、PHPで暗号化する際に'base64'せずに'binary'にすることができましたが、修正後でもエラーが出ており上手く動きません。
156
+
157
+
158
+
95
159
  ### 補足情報(FW/ツールのバージョンなど)
96
160
 
97
161
  暗号化する際に『aes-256-ecb』を使用するのはよくないことは承知しております。