chengjie 9 月之前
父節點
當前提交
16a8e5d74e

+ 3 - 2
app.js

@@ -1,14 +1,15 @@
1 1
 //app.js
2 2
 App({
3 3
   globalData: {
4
-    version: "1.1.19",
4
+    Version: "1.1.22",
5 5
     IsProduction: true,
6
+    //IsProduction: false,
6 7
     ProgramID: 105,
7 8
     AppID: "wx1fef080f74481cbd",
8 9
     ProgramName: "数学计算题",
9 10
     ShareTitle: "认真练习,告别粗心",
10 11
     SharePath: "pages/index/index",
11
-    ShareImage: '../../pages/images/programsystem_screenshot_pic01.png',
12
+    ShareImage: '../../pages/images/program_share-a01.png',
12 13
 
13 14
     fileUrl: "https://math-1253256735.file.myqcloud.com/",
14 15
     serverUrl: "https://www.kylx365.com/apiData/",

+ 3 - 3
package4/main/buyad.wxml

@@ -7,15 +7,15 @@
7 7
       <view class='panel111' bindtap='gotoOrder'>
8 8
         直接购买
9 9
       </view>
10
-      <view class='line1'></view>
10
+      <!-- <view class='line1'></view>
11 11
       <view class='panel112 panel111' bindtap='gotoPackList'>
12 12
         优惠套装
13
-      </view>
13
+      </view> -->
14 14
     </view>
15 15
     <view class='number'>{{Price}}元</view>
16 16
   </view>
17 17
 
18
-  <image src='../images/pay_shoppingguide_illus_02.png' class="pay_shoppingguide_illus_02" bindtap='gotoGiftList' />
18
+  <!-- <image src='../images/pay_shoppingguide_illus_02.png' class="pay_shoppingguide_illus_02" bindtap='gotoGiftList' /> -->
19 19
   
20 20
   <button class='text1' open-type="share">推荐给家长</button>
21 21
   <image src='../images/pay_shoppingguide_footer.png' class="pay_shoppingguide_footer" />

+ 2 - 1
package4/main/buyad.wxss

@@ -12,6 +12,7 @@
12 12
 .panel1 {
13 13
   width: 610rpx;
14 14
   margin-top: 30rpx;
15
+  margin-bottom: 60rpx;
15 16
   justify-content: flex-start;
16 17
   border-radius: 10rpx;
17 18
   box-shadow: 0 20rpx 1rpx #AE5138,
@@ -33,7 +34,7 @@
33 34
 }
34 35
 
35 36
 .panel111{
36
-  width: 304rpx;
37
+  width:100%;
37 38
   height:120rpx;
38 39
   line-height: 120rpx;
39 40
   text-align: center;

二進制
pages/images/cpxl_ad_01.gif


二進制
pages/images/cpxl_logo_01.png


二進制
pages/images/cpxl_logo_02.png


二進制
pages/images/cpxl_logo_03.png


二進制
pages/images/cpxl_logo_04.png


二進制
pages/images/cpxl_logo_05.png


二進制
pages/images/cpxl_logo_06.png


二進制
pages/images/cpxl_logo_07.png


二進制
pages/images/cpxl_pic_01.png


二進制
pages/images/cpxl_t01.png


二進制
pages/images/cpxl_t02.png


二進制
pages/images/cpxl_t03.png


二進制
pages/images/program_share-a01.png


二進制
pages/images/programsystem_screenshot_pic01.png


+ 2 - 2
pages/index/index.js

@@ -6,7 +6,7 @@ var timeout2, timeout3;
6 6
 
7 7
 Page({
8 8
   data: {
9
-    version: app.globalData.version,
9
+    version: app.globalData.Version,
10 10
   },
11 11
   onLoad: function (options) {
12 12
     if (options) {
@@ -92,7 +92,7 @@ Page({
92 92
         System: app.globalData.systemInfo.system,
93 93
         Platform: app.globalData.systemInfo.platform,
94 94
         SDKVersion: app.globalData.systemInfo.SDKVersion,
95
-        ProgramVersion: app.globalData.version,
95
+        ProgramVersion: app.globalData.Version,
96 96
       }, function (data) {
97 97
         //console.log("UserInfo:" + data);
98 98
         if (!data) {

+ 1 - 1
pages/main/answer.js

@@ -4,7 +4,7 @@ import server from '../../utils/main';
4 4
 const app = getApp()
5 5
 Page({
6 6
   data: {
7
-    version: app.globalData.version,
7
+    version: app.globalData.Version,
8 8
     IsEdit: false,
9 9
     ListHeight2: 600,
10 10
     SelectedCount: 0,

+ 2 - 24
pages/main/default.js

@@ -10,7 +10,8 @@ var isMiaoguoADShow = false;
10 10
 
11 11
 Page({
12 12
   data: {
13
-    version: app.globalData.version,
13
+    version: app.globalData.Version,
14
+    ProgramName:app.globalData.ProgramName,
14 15
     FileUrl: app.globalData.fileUrl,
15 16
     NickName: "陌生用户",
16 17
     IsMember: 1,
@@ -78,29 +79,6 @@ Page({
78 79
         that.showHelp();
79 80
       });
80 81
     }
81
-
82
-    common.getStorageValue(this, "IsMiaoguoAD", true, function () { });
83
-
84
-    var miaoguoADTime = wx.getStorageSync("miaoguoADTime");
85
-    if (miaoguoADTime) {
86
-      if (this.data.IsShow == 1 && this.data.IsMember == 1 && isMiaoguoADShow && common.formatTime(new Date()) >= miaoguoADTime) {
87
-        this.setData({
88
-          IsMiaoguoAD2: 1,
89
-        });
90
-      }
91
-    }
92
-    else {
93
-      wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 1, new Date())));
94
-    }
95
-
96
-    isMiaoguoADShow = true;
97
-
98
-    if (app.globalData.IsShowMiaoguo){
99
-      this.setData({
100
-        IsShowMiaoguo:1,
101
-      });
102
-      app.globalData.IsShowMiaoguo=false;
103
-    }
104 82
   },
105 83
   downloadUserAvatar: function () {
106 84
     var avatar = wx.getStorageSync("Avatar");

+ 57 - 163
pages/main/default.wxml

@@ -21,8 +21,7 @@
21 21
         </view>
22 22
         <view class="panel001 FlexRow">
23 23
           <view class="panel0010 FlexRow">
24
-            <image wx:for="{{[1,2,3,4]}}" wx:key="index" bindtap='gotoList' data-id="{{item}}"
25
-              class="homepage_question_illus_grade01" src="../images/homepage_question_illus_grade0{{item}}.png" />
24
+            <image wx:for="{{[1,2,3,4]}}" wx:key="index" bindtap='gotoList' data-id="{{item}}" class="homepage_question_illus_grade01" src="../images/homepage_question_illus_grade0{{item}}.png" />
26 25
           </view>
27 26
         </view>
28 27
         <view class="panel0011">
@@ -35,11 +34,12 @@
35 34
           <view class="panel0020 FlexRow">
36 35
             <view class="panel00200 FlexColumn">
37 36
               <view class="textTitle3">
38
-              <view class="textTitle4">练习记录</view>
37
+                <view class="textTitle4">练习记录</view>
39 38
                 <view class="textTitle5">练习记录</view>
40 39
               </view>
41 40
               <view class="line3"></view>
42
-              <view class="panel002000 FlexRow"><view class="text1">试卷张数</view>
41
+              <view class="panel002000 FlexRow">
42
+                <view class="text1">试卷张数</view>
43 43
                 <view class="text2">{{AnswerLength}}</view>
44 44
               </view>
45 45
               <view class="line4 line3"></view>
@@ -63,190 +63,84 @@
63 63
               </view>
64 64
             </view>
65 65
             <view class="panel00201 FlexRow" bindtap="gotoMemberCenter">
66
-              <image wx:if="{{!IsAccredit}}" class="universalpic_face_default_black_size01"
67
-                src="../images/universalpic_face_default_black_size01.png" bindtap='gotoBindGetUserInfo' />
66
+              <image wx:if="{{!IsAccredit}}" class="universalpic_face_default_black_size01" src="../images/universalpic_face_default_black_size01.png" bindtap='gotoBindGetUserInfo' />
68 67
               <image wx:if="{{IsAccredit}}" class="universalpic_face_default_black_size01" src="{{AvatarUrl}}" />
69 68
               <image wx:if="{{IsRemind}}" src='../images/message_home_01.png' class="message_home_01" />
70
-  
69
+
71 70
             </view>
72 71
           </view>
73 72
           <image class="homepage_clipboard_illus_clip" src="../images/homepage_clipboard_illus_clip.png" />
74 73
           <image class="homepage_clipboard_illus_ruler" src="../images/homepage_clipboard_illus_ruler.png" />
75
-
76 74
         </view>
77
-
78
-        <!-- <image class="universalpic_line_zigzag_brown_down" src="../images/universalpic_line_zigzag_brown_down.png" />
79
-        <image class="universalpic_line_zigzag_brown_up" src="../images/universalpic_line_zigzag_brown_up.png" />
80
-        <view class="panel003 circularBottom FlexColumn">
81
-          <view class="panel0030 FlexRow">
82
-            <view class="panel00300 FlexColumn">
83
-              <text class="text">©2018 唱意教育 - 数学计算题\n微信小程序 版本 {{version}}</text>
84
-              <view class="panel003000 FlexRow">
85
-                <view bindtap='gotoHelp'>帮助</view>
86
-                <view class="line"></view>
87
-                <view bindtap='gotoFeedback'>反馈</view>
88
-                <view class="line"></view>
89
-                <view bindtap='gotoFeedback'>合作</view>
90
-              </view>
91
-            </view>
92
-            <button class="btn4 btn0" open-type="share">
93
-              <view class="btn5 btn10 FlexColumn">
94
-                <image class="universalpic_share_size01" src="../images/universalpic_share_size01.png" />
95
-                <view>分享</view>
96
-              </view>
97
-            </button>
98
-
99
-          </view>
100
-
101
-          <view class="panel0031 FlexColumn">
102
-            <view class="panel00310 FlexColumn">
103
-              唱意教育其它练习产品
104
-            </view>
105
-            <view class="line"></view>
106
-            <block wx:for="{{ProgramList}}" wx:key="index">
107
-              <view class="panel00311 FlexRow" bindtap='switchProgram' data-appid='{{item.appId}}' data-path='{{item.path}}'>
108
-                <view class="panel003110 FlexRow">
109
-                  <image class="universalpic_product_kousuan_icon_size01" src="../images/{{item.imageName}}.png" />
110
-                  <view class="text">{{item.Name}}</view>
111
-                </view>
112
-                <image class="universalpic_indicator_maroon" src="../images/universalpic_indicator_pink.png" />
113
-              </view>
114
-              <view class="line"></view>
115
-
116
-            </block>
117
-            <view class="index5 FlexColumn" wx:if="{{IsShow==1}}">
118
-              <image src='../images/home_banner_footer600.png' class="home_banner" bindtap='goto' data-url='../../package4/main/newuser' />
119
-            </view>
120
-          </view>
121
-        </view> 
122
-        <view style="height:100rpx;width:100%"></view>
123
-        -->
124 75
       </view>
125 76
     </view>
126 77
     <view class="panel1 FlesColumn" wx:if="{{IsShow==1}}">
127 78
       <view class="panelOther FlexRow">
128 79
         <view class="panelOther1">其它产品</view>
129
-        <image src='../images/home_triangle_up.png' class="home_triangle_up" />
80
+        <image src='../images/cpxl_pic_01.png' class="home_triangle_up" />
130 81
       </view>
131 82
       <view class="panelProduct FlexColumn">
132
-        <view class="panelProduct10 panelProduct0 FlexColumn">
133
-          <view class="panelProduct1">全科练习</view>
134
-          <view class="panelProduct3 FlexRow" bindtap="showMiaoguo">
135
-            <image src='../images/sofewareicon_mg.png' class="sofewareicon_mg" />
136
-            <view class="panelProduct31 FlexColumn">
137
-              <view class="panelProduct311">秒过</view>
138
-              <view class="panelProduct312">基础知识记忆工具</view>
139
-            </view>
83
+        <image src="../images/cpxl_t01.png" class="cpxl_t01"></image>
84
+        <view class="panelProduct1 FlexRow">
85
+          <view class="panelProduct11 FlexColumn" bind:tap="switchProgram" data-appid="wxa5e33c61fe37dd01">
86
+            <image src="../images/cpxl_logo_01.png" class="cpxl_logo_01"></image>
87
+            <view class="panelProduct111">注意力</view>
88
+            <view class="panelProduct112">好玩的注意力训练工具</view>
89
+            <view class="panelProduct113">免费</view>
90
+          </view>
91
+          <view class="panelProduct11 FlexColumn" bind:tap="switchProgram" data-appid="wxb54a6d5aff836ee3">
92
+            <image src="../images/cpxl_logo_02.png" class="cpxl_logo_01"></image>
93
+            <view class="panelProduct111">英语自然拼读</view>
94
+            <view class="panelProduct112">词汇大全+点读练习</view>
95
+            <view class="panelProduct113">免费</view>
140 96
           </view>
141 97
         </view>
142
-
143
-        <view class="panelProduct1">单科练习</view>
144
-        <view class="panelProduct10 FlexRow" style="width:100%;">
145
-          <view class="panelProduct0 FlexColumn">
146
-            <view class="panelProduct2">数学</view>
147
-            <view class="panelProduct3 FlexRow" bindtap='switchProgram' data-appid='wxa5441bbf344692ba'>
148
-              <image src='../images/sofewareicon_ks.png' class="sofewareicon_mg" />
149
-              <view class="panelProduct31 FlexColumn">
150
-                <view class="panelProduct311">口算星球</view>
151
-                <view class="panelProduct312">好玩的口算敏捷练习</view>
152
-              </view>
153
-            </view>
154
-            <view class="panelProduct3 FlexRow" bindtap='switchProgram' data-appid='wx1fef080f74481cbd'>
155
-              <image src='../images/sofewareicon_jst.png' class="sofewareicon_mg" />
156
-              <view class="panelProduct31 FlexColumn">
157
-                <view class="panelProduct311">计算题打印</view>
158
-                <view class="panelProduct312">打印竖式横式计算题</view>
159
-              </view>
160
-            </view>
98
+        <image src="../images/cpxl_t02.png" class="cpxl_t01 cpxl_t02"></image>
99
+        <view class="panelProduct1 panelProduct100 FlexRow">
100
+          <view class="panelProduct11 FlexColumn" bind:tap="switchProgram" data-appid="wxa5441bbf344692ba">
101
+            <image src="../images/cpxl_logo_03.png" class="cpxl_logo_01"></image>
102
+            <view class="panelProduct111">练口算</view>
103
+            <view class="panelProduct112">好玩的口算敏捷训练</view>
161 104
           </view>
162
-          <view class="panelProduct0 FlexColumn">
163
-            <view class="panelProduct2">语文</view>
164
-            <view class="panelProduct3 FlexRow" bindtap='switchProgram' data-appid='wx331e8dd070f01d0e'>
165
-              <image src='../images/sofewareicon_py.png' class="sofewareicon_mg" />
166
-              <view class="panelProduct31 FlexColumn">
167
-                <view class="panelProduct311">汉语拼音</view>
168
-                <view class="panelProduct312">纯正发音练习</view>
169
-              </view>
170
-            </view>
171
-            <view class="panelProduct3 FlexRow" bindtap='switchProgram' data-appid='wx313a8f2c0741efe1'>
172
-              <image src='../images/sofewareicon_sz.png' class="sofewareicon_mg" />
173
-              <view class="panelProduct31 FlexColumn">
174
-                <view class="panelProduct311">识字</view>
175
-                <view class="panelProduct312">小学六年课本同步</view>
176
-              </view>
177
-            </view>
105
+          <view class="panelProduct11 FlexColumn" bind:tap="switchProgram" data-appid="wx1fef080f74481cbd">
106
+            <image src="../images/cpxl_logo_04.png" class="cpxl_logo_01"></image>
107
+            <view class="panelProduct111">练笔算</view>
108
+            <view class="panelProduct112">竖式计算题出题+打印</view>
178 109
           </view>
179 110
         </view>
180
-
181
-        <view style="width:100%;height:20rpx;"></view>
182
-        <view class="panelProduct10 panelProduct0 FlexColumn" bindtap='switchProgram' data-appid='wxb54a6d5aff836ee3'>
183
-          <view class="panelProduct1">英语</view>
184
-          <view class="panelProduct3 FlexRow">
185
-            <image src='../images/sofewareicon_pd.png' class="sofewareicon_mg" />
186
-            <view class="panelProduct31 FlexColumn">
187
-              <view class="panelProduct311">自然拼读</view>
188
-              <view class="panelProduct312">英语国家母语学习法</view>
189
-            </view>
111
+        <view class="panelProduct1 FlexRow">
112
+          <view class="panelProduct11 FlexColumn" bind:tap="switchProgram" data-appid="wx331e8dd070f01d0e">
113
+            <image src="../images/cpxl_logo_05.png" class="cpxl_logo_01"></image>
114
+            <view class="panelProduct111">汉语拼音</view>
115
+            <view class="panelProduct112">易错字词发音点读</view>
116
+            <view class="panelProduct113">免费</view>
117
+          </view>
118
+          <view class="panelProduct11 FlexColumn" bind:tap="switchProgram" data-appid="wx313a8f2c0741efe1">
119
+            <image src="../images/cpxl_logo_06.png" class="cpxl_logo_01"></image>
120
+            <view class="panelProduct111">识字表点读</view>
121
+            <view class="panelProduct112">一到六年级语文书同步</view>
122
+            <view class="panelProduct113">免费</view>
190 123
           </view>
191 124
         </view>
192
-        <view style="width:100%;height:60rpx;"></view>
193
-      </view>
194
-
195
-      <image bindtap="showMiaoguo" src='../images/home_banner.png' class="home_banner" />
196
-
197
-    </view>
198
-  </view>
199
-</view>
200
-<image hidden="{{HelpHidden1}}" bindtap='closeHelp' class="Help_aside_homepage"
201
-  src="../images/Help_aside_homepage.png" />
202
-
203
-<view class="HelpInfo2 FlexColumn" style='height:{{Height}}rpx;' wx:if="{{IsMiaoguoAD2==1}}">
204
-  <view class="btn">
205
-    <view class="btn1 FlexColumn" catchtap="showMiaoguo">
206
-      <image src='../images/home_banner_window.png' class="home_banner_window" />
207
-      <view class="btn2">去领取</view>
208
-    </view>
209
-  </view>
210
-  <view class="close2 FlexColumn" bindtap='close' data-num="1">
211
-    以后再看
212
-  </view>
213
-  <view class="close FlexColumn" bindtap='close' data-num="0">
214
-    <image src='../images/02024.png' class="closeImage" />
215
-  </view>
216
-</view>
217
-
218
-<view class="HelpInfo2 FlexColumn" style='height:{{Height}}rpx;' wx:if="{{IsShowGift==1}}">
219
-  <view class="btn">
220
-    <view class="btn1 FlexColumn" catchtap="showMiaoguo">
221
-      <view class="HelpInfo21 FlexColumn">
222
-        <image src='../images/02014.png' class="png02014" />
223
-        <view class="HelpInfo211">有效期已延长</view>
224
-        <view class="HelpInfo212">计算题20天礼品卡已兑换成功</view>
125
+        <image src="../images/cpxl_t03.png" class="cpxl_t01 cpxl_t03"></image>
126
+        <view class="panelProduct1 FlexRow">
127
+          <view class="panelProduct11 panelProduct10 FlexColumn" bind:tap="switchProgram" data-appid="wx84b3feac6069eec3">
128
+            <image src="../images/cpxl_logo_07.png" class="cpxl_logo_01"></image>
129
+            <view class="panelProduct111">秒过 · 错题记忆卡</view>
130
+            <view class="panelProduct114">可以记牢一切基础知识的练习方法和工具。彻底解决语文字词、成语、诗词;英语单词、语法;数物化公式、定理;史地政必考要点等。</view>
131
+            <image src="../images/cpxl_ad_01.gif" class="cpxl_ad_01"></image>
132
+          </view>
133
+        </view>
134
+        <view class="panelProduct1 FlexColumn">
135
+          <view class="panelFooter1">2017-2025 {{ProgramName}}</view>
136
+          <view class="panelFooter2">唱意教育微信小程序 版本 {{version}}</view>
137
+        </view>
138
+        
225 139
       </view>
226
-      <view class="btn2" catchtap='goto' data-url='../../package4/main/getgiftlist'>查看记录</view>
227 140
     </view>
228 141
   </view>
229
-  <view class="close FlexColumn" bindtap='close' data-num="0">
230
-    <image src='../images/02024.png' class="closeImage" />
231
-  </view>
232
-</view>
233
-
234
-<view class="PanelMiaoguo FlexColumn" style='height:{{Height}}rpx;' wx:if="{{IsShowMiaoguo==1}}" catchtap="closeMiaoguo">
235
-  <view class="PanelMiaoguo1 FlexColumn">
236
-    <image src='../images/bm_sy_illus.png' class="bm_sy_illus"/>
237
-    <view class="Text1">该记的记不住</view>
238
-    <view class="Text2">用「秒过」</view>
239
-    <text class="Text3">帮助孩子记牢语数外基础知识的\n工具和练习方法</text>
240
-    <view class="Text4">了解详情,欢迎参加</view>
241
-    <view class="Text5">新手培训</view>
242
-    <view class="btn3 FlexColumn" bindtap='switchProgram' data-appid='wx84b3feac6069eec3'>
243
-      <image src='../images/bm_sy_banner-open.png' class="bm_sy_banner-open" />
244
-    </view>
245
-
246
-    <view class="btnReadme" catchtap='goto' data-url='../../package4/main/miaoguoreadme'></view>
247
-    <view class="btnRecord" catchtap='goto' data-url='../../package4/main/getgiftlist'></view>
248
-  </view>
249 142
 </view>
143
+<image hidden="{{HelpHidden1}}" bindtap='closeHelp' class="Help_aside_homepage" src="../images/Help_aside_homepage.png" />
250 144
 
251 145
 <audio hidden='true' id="myAudio"></audio>
252 146
 <canvas class='Canvas' canvas-id="MyCanvas"></canvas>

+ 80 - 34
pages/main/default.wxss

@@ -586,59 +586,105 @@ page{
586 586
   left:105rpx;
587 587
   z-index: 10;
588 588
 }
589
-
590 589
 .panelProduct{
591 590
   width:100%;
592
-  background-color: #fff;
591
+  background-color: #D5CAC6;
593 592
   align-items: flex-start;
594 593
 }
595
-.panelProduct0{
596
-  width:50%;
597
-  font-size:32rpx;
598
-  color:#4D4D4D;
599
-  justify-content: flex-start;
600
-  align-items: flex-start;
594
+
595
+.cpxl_t01{
596
+  width: 156rpx;
597
+  height:52rpx;
598
+  margin: 60rpx 0 0 50rpx;
601 599
 }
602
-.panelProduct1{
603
-  background-color: #fff;
604
-  margin: 50rpx 0 0 50rpx;
605
-  font-size:32rpx;
606
-  color:#4D4D4D;
600
+.cpxl_t02{
601
+  width: 190rpx;
602
+}
603
+.cpxl_t03{
604
+  width: 300rpx;
607 605
 }
608 606
 
609
-.panelProduct10{
607
+.panelProduct1{
610 608
   width:100%;
609
+  margin: 40rpx 0 20rpx 0;
611 610
 }
612 611
 
613
-.panelProduct2{
614
-  background-color: #fff;
615
-  margin: 0 0 0 50rpx;
616
-  font-size:32rpx;
617
-  color:#4D4D4D;
612
+.panelProduct100{
613
+  margin: 40rpx 0 0 0;
618 614
 }
619 615
 
620
-.panelProduct3{
621
-  width:300rpx;
622
-  margin:30rpx 0 0 50rpx;
623
-  justify-content: flex-start;
616
+.panelProduct11{
617
+  width:330rpx;
618
+  height:285rpx;
619
+  background: #F8F8F8;
620
+  border: 4rpx solid #B67249;
621
+  box-shadow: 0 16rpx 0 0 rgba(0,0,0,0.30), inset 0 -20rpx 0 0 rgba(0,0,0,0.20);
622
+  border-radius: 30rpx;
623
+  margin: 0 15rpx;
624
+  align-items: flex-start;
625
+  position: relative;
626
+}
627
+
628
+.panelProduct10{
629
+  width:690rpx;
630
+  height:811rpx;
624 631
 }
625 632
 
626
-.sofewareicon_mg{
627
-  width:66rpx;
628
-  height:66rpx;
633
+.cpxl_logo_01{
634
+  width:90rpx;
635
+  height:90rpx;
636
+  margin-left: 40rpx;
629 637
 }
630 638
 
631 639
 
632
-.panelProduct31{
633
-  margin:0 0 0 30rpx;
634
-  align-items: flex-start;
640
+.panelProduct111{
641
+  font-size: 34rpx;
642
+  font-weight: 600;
643
+  color:#1E1E1E;
644
+  margin: 20rpx 0 0 40rpx;
635 645
 }
636
-.panelProduct311{
637
-  font-size:28rpx;
646
+
647
+.panelProduct112{
648
+  font-weight: 400;
649
+  font-size: 24rpx;
650
+  color: #4D4D4D;
651
+  margin: 0 0 10rpx 40rpx;
652
+}
653
+.panelProduct113{
654
+  background: #B67249;
655
+  border-radius: 6rpx;
656
+  font-size: 20rpx;
657
+  color: #FFFFFF;
658
+  text-align: center;
659
+  width: 60rpx;
660
+  height:34rpx;
661
+  line-height: 34rpx;
662
+  position: absolute;
663
+  top:50rpx;
664
+  right:40rpx;
665
+}
666
+.panelProduct114{
667
+  font-weight: 400;
668
+  font-size: 24rpx;
669
+  color: #4D4D4D;
670
+  margin: 0 0 0 40rpx;
671
+  width: 610rpx;
672
+}
673
+.cpxl_ad_01{
674
+  width:610rpx;
675
+  height:410rpx;
676
+  margin: 40rpx 0 0 40rpx;
638 677
 }
639
-.panelProduct312{
640
-  font-size:20rpx;
641
-  color:#4D4D4D;
678
+
679
+.panelFooter1{
680
+  font-size:24rpx;
681
+  color:#695852;
682
+  margin-top: 20rpx;
683
+}
684
+.panelFooter2{
685
+  font-size:24rpx;
686
+  color:#695852;
687
+  margin-bottom: 100rpx;
642 688
 }
643 689
 
644 690
 .home_banner{

+ 3 - 1
pages/main/detail.js

@@ -12,7 +12,7 @@ const waitTime = ["", "10秒钟", "15秒钟", "20秒钟", "25秒钟"];
12 12
 
13 13
 Page({
14 14
   data: {
15
-    version: app.globalData.version,
15
+    version: app.globalData.Version,
16 16
     IsShowMenu: false,
17 17
     filter: 'horizontal',
18 18
     //filter: 'vertical',
@@ -348,6 +348,8 @@ Page({
348 348
             height = 210;
349 349
           else if (item.PageCount == 15)
350 350
             height = 250;
351
+          else if (item.PageCount == 9)
352
+            height = 400;
351 353
         }
352 354
         //括号
353 355
         var index = 0;

+ 1 - 1
pages/main/item.js

@@ -9,7 +9,7 @@ var AnswerID = 0;
9 9
 
10 10
 Page({
11 11
   data: {
12
-    version: app.globalData.version,
12
+    version: app.globalData.Version,
13 13
     IsPlaying: 0,
14 14
     PlayStr: "本",
15 15
     selectTab0: "btn1",

+ 20 - 1
pages/main/list.js

@@ -10,7 +10,7 @@ var arrDifficult = ["", "", "简单", "普通", "困难"];
10 10
 
11 11
 Page({
12 12
   data: {
13
-    version: app.globalData.version,
13
+    version: app.globalData.Version,
14 14
     filter: 'all',
15 15
     CategoryID: 1,
16 16
     CategoryNum: 1,
@@ -125,6 +125,25 @@ Page({
125 125
         }
126 126
       }
127 127
     }
128
+
129
+    for (var j = 0; j < list.length; j++) {
130
+        var item = list[j];
131
+        switch (item.ID){
132
+            case 167:
133
+            case 174:
134
+            case 166:
135
+            case 190:
136
+            case 191:
137
+            case 192:
138
+            case 193:
139
+            case 164:
140
+            case 165:
141
+            case 195:
142
+                item.CategoryLevel="乘除运算3级"
143
+                break;
144
+        }
145
+    }
146
+
128 147
     this.setData({
129 148
       QuestionTypeList: list,
130 149
     });

+ 1 - 1
pages/main/userinfo.js

@@ -6,7 +6,7 @@ const app = getApp();
6 6
 Page({
7 7
   data: {
8 8
     FileUrl: app.globalData.imageUrl,
9
-    Version: app.globalData.version,
9
+    Version: app.globalData.Version,
10 10
     ProgramName: app.globalData.ProgramName,
11 11
   },
12 12
   onLoad: function (options) {

+ 4 - 4
pages/main/userinfo.wxml

@@ -37,7 +37,7 @@
37 37
         <image src='../images/Arrow.png' class="Arrow" />
38 38
       </view>
39 39
     </view>
40
-    <view class="lineWidthAll FlexRow">
40
+    <!-- <view class="lineWidthAll FlexRow">
41 41
       <view class="lineWidth720"></view>
42 42
     </view>
43 43
     <view class="panelItem FlexRow" bindtap='goto' data-url='../../package4/main/giftlist'>
@@ -54,7 +54,7 @@
54 54
       <view class="panelItem2 FlexRow">
55 55
         <image src='../images/Arrow.png' class="Arrow" />
56 56
       </view>
57
-    </view>
57
+    </view> -->
58 58
     <view class='lineFooter'></view>
59 59
 
60 60
     <view class="panelTitle FlexRow">
@@ -69,7 +69,7 @@
69 69
         <image src='../images/Arrow.png' class="Arrow" />
70 70
       </view>
71 71
     </view>
72
-    <view class="lineWidthAll FlexRow">
72
+    <!-- <view class="lineWidthAll FlexRow">
73 73
       <view class="lineWidth720"></view>
74 74
     </view>
75 75
     <view class="panelItem0 panelItem FlexRow" bindtap='goto' data-url='../../package4/main/list?IsGift=0'>
@@ -92,7 +92,7 @@
92 92
       <view class="panelItem2 FlexRow">
93 93
         <image src='../images/Arrow.png' class="Arrow" />
94 94
       </view>
95
-    </view>
95
+    </view> -->
96 96
     <view class='lineFooter'></view>
97 97
   </block>
98 98
   <view class="panelTitle FlexRow">

+ 2 - 1
project.config.json

@@ -27,7 +27,8 @@
27 27
     "showES6CompileOption": false,
28 28
     "useCompilerPlugins": false,
29 29
     "minifyWXML": true,
30
-    "useStaticServer": true
30
+    "useStaticServer": true,
31
+    "condition": false
31 32
   },
32 33
   "compileType": "miniprogram",
33 34
   "libVersion": "2.15.0",

+ 6 - 1
project.private.config.json

@@ -57,5 +57,10 @@
57 57
         }
58 58
       ]
59 59
     }
60
-  }
60
+  },
61
+  "setting": {
62
+    "compileHotReLoad": true
63
+  },
64
+  "libVersion": "3.1.5",
65
+  "projectname": "%E6%95%B0%E5%AD%A6%E8%AE%A1%E7%AE%97%E9%A2%98"
61 66
 }

+ 402 - 402
utils/lib/AES.js

@@ -1,402 +1,402 @@
1
-(function(){
2
-
3
-var C = (typeof window === 'undefined') ? require('./Crypto').Crypto : window.Crypto;
4
-
5
-// Shortcuts
6
-var util = C.util,
7
-    charenc = C.charenc,
8
-    UTF8 = charenc.UTF8;
9
-
10
-// Precomputed SBOX
11
-var SBOX = [ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
12
-             0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
13
-             0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
14
-             0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
15
-             0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
16
-             0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
17
-             0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
18
-             0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
19
-             0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
20
-             0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
21
-             0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
22
-             0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
23
-             0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
24
-             0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
25
-             0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
26
-             0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
27
-             0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
28
-             0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
29
-             0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
30
-             0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
31
-             0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
32
-             0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
33
-             0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
34
-             0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
35
-             0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
36
-             0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
37
-             0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
38
-             0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
39
-             0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
40
-             0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
41
-             0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
42
-             0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 ];
43
-
44
-// Compute inverse SBOX lookup table
45
-for (var INVSBOX = [], i = 0; i < 256; i++) INVSBOX[SBOX[i]] = i;
46
-
47
-// Compute mulitplication in GF(2^8) lookup tables
48
-var MULT2 = [],
49
-    MULT3 = [],
50
-    MULT9 = [],
51
-    MULTB = [],
52
-    MULTD = [],
53
-    MULTE = [];
54
-
55
-function xtime(a, b) {
56
-	for (var result = 0, i = 0; i < 8; i++) {
57
-		if (b & 1) result ^= a;
58
-		var hiBitSet = a & 0x80;
59
-		a = (a << 1) & 0xFF;
60
-		if (hiBitSet) a ^= 0x1b;
61
-		b >>>= 1;
62
-	}
63
-	return result;
64
-}
65
-
66
-for (var i = 0; i < 256; i++) {
67
-	MULT2[i] = xtime(i,2);
68
-	MULT3[i] = xtime(i,3);
69
-	MULT9[i] = xtime(i,9);
70
-	MULTB[i] = xtime(i,0xB);
71
-	MULTD[i] = xtime(i,0xD);
72
-	MULTE[i] = xtime(i,0xE);
73
-}
74
-
75
-// Precomputed RCon lookup
76
-var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
77
-
78
-// Inner state
79
-var state = [[], [], [], []],
80
-    keylength,
81
-    nrounds,
82
-    keyschedule;
83
-
84
-var AES = C.AES = {
85
-
86
-	/**
87
-	 * Public API
88
-	 */
89
-
90
-	encrypt: function (message, password, options) {
91
-
92
-		options = options || {};
93
-
94
-		// Determine mode
95
-		var mode = options.mode || new C.mode.OFB;
96
-
97
-		// Allow mode to override options
98
-		if (mode.fixOptions) mode.fixOptions(options);
99
-
100
-		var
101
-
102
-			// Convert to bytes if message is a string
103
-			m = (
104
-				message.constructor == String ?
105
-				UTF8.stringToBytes(message) :
106
-				message
107
-			),
108
-
109
-			// Generate random IV
110
-			iv = options.iv || util.randomBytes(AES._blocksize * 4),
111
-
112
-			// Generate key
113
-			k = (
114
-				password.constructor == String ?
115
-				// Derive key from passphrase
116
-				C.PBKDF2(password, iv, 32, { asBytes: true }) :
117
-				// else, assume byte array representing cryptographic key
118
-				password
119
-			);
120
-
121
-		// Encrypt
122
-		AES._init(k);
123
-		mode.encrypt(AES, m, iv);
124
-
125
-		// Return ciphertext
126
-		m = options.iv ? m : iv.concat(m);
127
-		return (options && options.asBytes) ? m : util.bytesToBase64(m);
128
-
129
-	},
130
-
131
-	decrypt: function (ciphertext, password, options) {
132
-
133
-		options = options || {};
134
-
135
-		// Determine mode
136
-		var mode = options.mode || new C.mode.OFB;
137
-
138
-		// Allow mode to override options
139
-		if (mode.fixOptions) mode.fixOptions(options);
140
-
141
-		var
142
-
143
-			// Convert to bytes if ciphertext is a string
144
-			c = (
145
-				ciphertext.constructor == String ?
146
-				util.base64ToBytes(ciphertext):
147
-			    ciphertext
148
-			),
149
-
150
-			// Separate IV and message
151
-			iv = options.iv || c.splice(0, AES._blocksize * 4),
152
-
153
-			// Generate key
154
-			k = (
155
-				password.constructor == String ?
156
-				// Derive key from passphrase
157
-				C.PBKDF2(password, iv, 32, { asBytes: true }) :
158
-				// else, assume byte array representing cryptographic key
159
-				password
160
-			);
161
-
162
-		// Decrypt
163
-		AES._init(k);
164
-		mode.decrypt(AES, c, iv);
165
-
166
-		// Return plaintext
167
-		return (options && options.asBytes) ? c : UTF8.bytesToString(c);
168
-
169
-	},
170
-
171
-
172
-	/**
173
-	 * Package private methods and properties
174
-	 */
175
-
176
-	_blocksize: 4,
177
-
178
-	_encryptblock: function (m, offset) {
179
-
180
-		// Set input
181
-		for (var row = 0; row < AES._blocksize; row++) {
182
-			for (var col = 0; col < 4; col++)
183
-				state[row][col] = m[offset + col * 4 + row];
184
-		}
185
-
186
-		// Add round key
187
-		for (var row = 0; row < 4; row++) {
188
-			for (var col = 0; col < 4; col++)
189
-				state[row][col] ^= keyschedule[col][row];
190
-		}
191
-
192
-		for (var round = 1; round < nrounds; round++) {
193
-
194
-			// Sub bytes
195
-			for (var row = 0; row < 4; row++) {
196
-				for (var col = 0; col < 4; col++)
197
-					state[row][col] = SBOX[state[row][col]];
198
-			}
199
-
200
-			// Shift rows
201
-			state[1].push(state[1].shift());
202
-			state[2].push(state[2].shift());
203
-			state[2].push(state[2].shift());
204
-			state[3].unshift(state[3].pop());
205
-
206
-			// Mix columns
207
-			for (var col = 0; col < 4; col++) {
208
-
209
-				var s0 = state[0][col],
210
-				    s1 = state[1][col],
211
-				    s2 = state[2][col],
212
-				    s3 = state[3][col];
213
-
214
-				state[0][col] = MULT2[s0] ^ MULT3[s1] ^ s2 ^ s3;
215
-				state[1][col] = s0 ^ MULT2[s1] ^ MULT3[s2] ^ s3;
216
-				state[2][col] = s0 ^ s1 ^ MULT2[s2] ^ MULT3[s3];
217
-				state[3][col] = MULT3[s0] ^ s1 ^ s2 ^ MULT2[s3];
218
-
219
-			}
220
-
221
-			// Add round key
222
-			for (var row = 0; row < 4; row++) {
223
-				for (var col = 0; col < 4; col++)
224
-					state[row][col] ^= keyschedule[round * 4 + col][row];
225
-			}
226
-
227
-		}
228
-
229
-		// Sub bytes
230
-		for (var row = 0; row < 4; row++) {
231
-			for (var col = 0; col < 4; col++)
232
-				state[row][col] = SBOX[state[row][col]];
233
-		}
234
-
235
-		// Shift rows
236
-		state[1].push(state[1].shift());
237
-		state[2].push(state[2].shift());
238
-		state[2].push(state[2].shift());
239
-		state[3].unshift(state[3].pop());
240
-
241
-		// Add round key
242
-		for (var row = 0; row < 4; row++) {
243
-			for (var col = 0; col < 4; col++)
244
-				state[row][col] ^= keyschedule[nrounds * 4 + col][row];
245
-		}
246
-
247
-		// Set output
248
-		for (var row = 0; row < AES._blocksize; row++) {
249
-			for (var col = 0; col < 4; col++)
250
-				m[offset + col * 4 + row] = state[row][col];
251
-		}
252
-
253
-	},
254
-
255
-	_decryptblock: function (c, offset) {
256
-
257
-		// Set input
258
-		for (var row = 0; row < AES._blocksize; row++) {
259
-			for (var col = 0; col < 4; col++)
260
-				state[row][col] = c[offset + col * 4 + row];
261
-		}
262
-
263
-		// Add round key
264
-		for (var row = 0; row < 4; row++) {
265
-			for (var col = 0; col < 4; col++)
266
-				state[row][col] ^= keyschedule[nrounds * 4 + col][row];
267
-		}
268
-
269
-		for (var round = 1; round < nrounds; round++) {
270
-
271
-			// Inv shift rows
272
-			state[1].unshift(state[1].pop());
273
-			state[2].push(state[2].shift());
274
-			state[2].push(state[2].shift());
275
-			state[3].push(state[3].shift());
276
-
277
-			// Inv sub bytes
278
-			for (var row = 0; row < 4; row++) {
279
-				for (var col = 0; col < 4; col++)
280
-					state[row][col] = INVSBOX[state[row][col]];
281
-			}
282
-
283
-			// Add round key
284
-			for (var row = 0; row < 4; row++) {
285
-				for (var col = 0; col < 4; col++)
286
-					state[row][col] ^= keyschedule[(nrounds - round) * 4 + col][row];
287
-			}
288
-
289
-			// Inv mix columns
290
-			for (var col = 0; col < 4; col++) {
291
-
292
-				var s0 = state[0][col],
293
-				    s1 = state[1][col],
294
-				    s2 = state[2][col],
295
-				    s3 = state[3][col];
296
-
297
-				state[0][col] = MULTE[s0] ^ MULTB[s1] ^ MULTD[s2] ^ MULT9[s3];
298
-				state[1][col] = MULT9[s0] ^ MULTE[s1] ^ MULTB[s2] ^ MULTD[s3];
299
-				state[2][col] = MULTD[s0] ^ MULT9[s1] ^ MULTE[s2] ^ MULTB[s3];
300
-				state[3][col] = MULTB[s0] ^ MULTD[s1] ^ MULT9[s2] ^ MULTE[s3];
301
-
302
-			}
303
-
304
-		}
305
-
306
-		// Inv shift rows
307
-		state[1].unshift(state[1].pop());
308
-		state[2].push(state[2].shift());
309
-		state[2].push(state[2].shift());
310
-		state[3].push(state[3].shift());
311
-
312
-		// Inv sub bytes
313
-		for (var row = 0; row < 4; row++) {
314
-			for (var col = 0; col < 4; col++)
315
-				state[row][col] = INVSBOX[state[row][col]];
316
-		}
317
-
318
-		// Add round key
319
-		for (var row = 0; row < 4; row++) {
320
-			for (var col = 0; col < 4; col++)
321
-				state[row][col] ^= keyschedule[col][row];
322
-		}
323
-
324
-		// Set output
325
-		for (var row = 0; row < AES._blocksize; row++) {
326
-			for (var col = 0; col < 4; col++)
327
-				c[offset + col * 4 + row] = state[row][col];
328
-		}
329
-
330
-	},
331
-
332
-
333
-	/**
334
-	 * Private methods
335
-	 */
336
-
337
-	_init: function (k) {
338
-		keylength = k.length / 4;
339
-		nrounds = keylength + 6;
340
-		AES._keyexpansion(k);
341
-	},
342
-
343
-	// Generate a key schedule
344
-	_keyexpansion: function (k) {
345
-
346
-		keyschedule = [];
347
-
348
-		for (var row = 0; row < keylength; row++) {
349
-			keyschedule[row] = [
350
-				k[row * 4],
351
-				k[row * 4 + 1],
352
-				k[row * 4 + 2],
353
-				k[row * 4 + 3]
354
-			];
355
-		}
356
-
357
-		for (var row = keylength; row < AES._blocksize * (nrounds + 1); row++) {
358
-
359
-			var temp = [
360
-				keyschedule[row - 1][0],
361
-				keyschedule[row - 1][1],
362
-				keyschedule[row - 1][2],
363
-				keyschedule[row - 1][3]
364
-			];
365
-
366
-			if (row % keylength == 0) {
367
-
368
-				// Rot word
369
-				temp.push(temp.shift());
370
-
371
-				// Sub word
372
-				temp[0] = SBOX[temp[0]];
373
-				temp[1] = SBOX[temp[1]];
374
-				temp[2] = SBOX[temp[2]];
375
-				temp[3] = SBOX[temp[3]];
376
-
377
-				temp[0] ^= RCON[row / keylength];
378
-
379
-			} else if (keylength > 6 && row % keylength == 4) {
380
-
381
-				// Sub word
382
-				temp[0] = SBOX[temp[0]];
383
-				temp[1] = SBOX[temp[1]];
384
-				temp[2] = SBOX[temp[2]];
385
-				temp[3] = SBOX[temp[3]];
386
-
387
-			}
388
-
389
-			keyschedule[row] = [
390
-				keyschedule[row - keylength][0] ^ temp[0],
391
-				keyschedule[row - keylength][1] ^ temp[1],
392
-				keyschedule[row - keylength][2] ^ temp[2],
393
-				keyschedule[row - keylength][3] ^ temp[3]
394
-			];
395
-
396
-		}
397
-
398
-	}
399
-
400
-};
401
-
402
-})();
1
+(function(){
2
+
3
+var C = (typeof window === 'undefined') ? require('./Crypto').Crypto : window.Crypto;
4
+
5
+// Shortcuts
6
+var util = C.util,
7
+    charenc = C.charenc,
8
+    UTF8 = charenc.UTF8;
9
+
10
+// Precomputed SBOX
11
+var SBOX = [ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
12
+             0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
13
+             0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
14
+             0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
15
+             0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
16
+             0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
17
+             0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
18
+             0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
19
+             0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
20
+             0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
21
+             0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
22
+             0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
23
+             0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
24
+             0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
25
+             0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
26
+             0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
27
+             0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
28
+             0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
29
+             0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
30
+             0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
31
+             0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
32
+             0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
33
+             0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
34
+             0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
35
+             0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
36
+             0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
37
+             0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
38
+             0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
39
+             0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
40
+             0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
41
+             0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
42
+             0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 ];
43
+
44
+// Compute inverse SBOX lookup table
45
+for (var INVSBOX = [], i = 0; i < 256; i++) INVSBOX[SBOX[i]] = i;
46
+
47
+// Compute mulitplication in GF(2^8) lookup tables
48
+var MULT2 = [],
49
+    MULT3 = [],
50
+    MULT9 = [],
51
+    MULTB = [],
52
+    MULTD = [],
53
+    MULTE = [];
54
+
55
+function xtime(a, b) {
56
+	for (var result = 0, i = 0; i < 8; i++) {
57
+		if (b & 1) result ^= a;
58
+		var hiBitSet = a & 0x80;
59
+		a = (a << 1) & 0xFF;
60
+		if (hiBitSet) a ^= 0x1b;
61
+		b >>>= 1;
62
+	}
63
+	return result;
64
+}
65
+
66
+for (var i = 0; i < 256; i++) {
67
+	MULT2[i] = xtime(i,2);
68
+	MULT3[i] = xtime(i,3);
69
+	MULT9[i] = xtime(i,9);
70
+	MULTB[i] = xtime(i,0xB);
71
+	MULTD[i] = xtime(i,0xD);
72
+	MULTE[i] = xtime(i,0xE);
73
+}
74
+
75
+// Precomputed RCon lookup
76
+var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
77
+
78
+// Inner state
79
+var state = [[], [], [], []],
80
+    keylength,
81
+    nrounds,
82
+    keyschedule;
83
+
84
+var AES = C.AES = {
85
+
86
+	/**
87
+	 * Public API
88
+	 */
89
+
90
+	encrypt: function (message, password, options) {
91
+
92
+		options = options || {};
93
+
94
+		// Determine mode
95
+		var mode = options.mode || new C.mode.OFB;
96
+
97
+		// Allow mode to override options
98
+		if (mode.fixOptions) mode.fixOptions(options);
99
+
100
+		var
101
+
102
+			// Convert to bytes if message is a string
103
+			m = (
104
+				message.constructor == String ?
105
+				UTF8.stringToBytes(message) :
106
+				message
107
+			),
108
+
109
+			// Generate random IV
110
+			iv = options.iv || util.randomBytes(AES._blocksize * 4),
111
+
112
+			// Generate key
113
+			k = (
114
+				password.constructor == String ?
115
+				// Derive key from passphrase
116
+				C.PBKDF2(password, iv, 32, { asBytes: true }) :
117
+				// else, assume byte array representing cryptographic key
118
+				password
119
+			);
120
+
121
+		// Encrypt
122
+		AES._init(k);
123
+		mode.encrypt(AES, m, iv);
124
+
125
+		// Return ciphertext
126
+		m = options.iv ? m : iv.concat(m);
127
+		return (options && options.asBytes) ? m : util.bytesToBase64(m);
128
+
129
+	},
130
+
131
+	decrypt: function (ciphertext, password, options) {
132
+
133
+		options = options || {};
134
+
135
+		// Determine mode
136
+		var mode = options.mode || new C.mode.OFB;
137
+
138
+		// Allow mode to override options
139
+		if (mode.fixOptions) mode.fixOptions(options);
140
+
141
+		var
142
+
143
+			// Convert to bytes if ciphertext is a string
144
+			c = (
145
+				ciphertext.constructor == String ?
146
+				util.base64ToBytes(ciphertext):
147
+			    ciphertext
148
+			),
149
+
150
+			// Separate IV and message
151
+			iv = options.iv || c.splice(0, AES._blocksize * 4),
152
+
153
+			// Generate key
154
+			k = (
155
+				password.constructor == String ?
156
+				// Derive key from passphrase
157
+				C.PBKDF2(password, iv, 32, { asBytes: true }) :
158
+				// else, assume byte array representing cryptographic key
159
+				password
160
+			);
161
+
162
+		// Decrypt
163
+		AES._init(k);
164
+		mode.decrypt(AES, c, iv);
165
+
166
+		// Return plaintext
167
+		return (options && options.asBytes) ? c : UTF8.bytesToString(c);
168
+
169
+	},
170
+
171
+
172
+	/**
173
+	 * Package private methods and properties
174
+	 */
175
+
176
+	_blocksize: 4,
177
+
178
+	_encryptblock: function (m, offset) {
179
+
180
+		// Set input
181
+		for (var row = 0; row < AES._blocksize; row++) {
182
+			for (var col = 0; col < 4; col++)
183
+				state[row][col] = m[offset + col * 4 + row];
184
+		}
185
+
186
+		// Add round key
187
+		for (var row = 0; row < 4; row++) {
188
+			for (var col = 0; col < 4; col++)
189
+				state[row][col] ^= keyschedule[col][row];
190
+		}
191
+
192
+		for (var round = 1; round < nrounds; round++) {
193
+
194
+			// Sub bytes
195
+			for (var row = 0; row < 4; row++) {
196
+				for (var col = 0; col < 4; col++)
197
+					state[row][col] = SBOX[state[row][col]];
198
+			}
199
+
200
+			// Shift rows
201
+			state[1].push(state[1].shift());
202
+			state[2].push(state[2].shift());
203
+			state[2].push(state[2].shift());
204
+			state[3].unshift(state[3].pop());
205
+
206
+			// Mix columns
207
+			for (var col = 0; col < 4; col++) {
208
+
209
+				var s0 = state[0][col],
210
+				    s1 = state[1][col],
211
+				    s2 = state[2][col],
212
+				    s3 = state[3][col];
213
+
214
+				state[0][col] = MULT2[s0] ^ MULT3[s1] ^ s2 ^ s3;
215
+				state[1][col] = s0 ^ MULT2[s1] ^ MULT3[s2] ^ s3;
216
+				state[2][col] = s0 ^ s1 ^ MULT2[s2] ^ MULT3[s3];
217
+				state[3][col] = MULT3[s0] ^ s1 ^ s2 ^ MULT2[s3];
218
+
219
+			}
220
+
221
+			// Add round key
222
+			for (var row = 0; row < 4; row++) {
223
+				for (var col = 0; col < 4; col++)
224
+					state[row][col] ^= keyschedule[round * 4 + col][row];
225
+			}
226
+
227
+		}
228
+
229
+		// Sub bytes
230
+		for (var row = 0; row < 4; row++) {
231
+			for (var col = 0; col < 4; col++)
232
+				state[row][col] = SBOX[state[row][col]];
233
+		}
234
+
235
+		// Shift rows
236
+		state[1].push(state[1].shift());
237
+		state[2].push(state[2].shift());
238
+		state[2].push(state[2].shift());
239
+		state[3].unshift(state[3].pop());
240
+
241
+		// Add round key
242
+		for (var row = 0; row < 4; row++) {
243
+			for (var col = 0; col < 4; col++)
244
+				state[row][col] ^= keyschedule[nrounds * 4 + col][row];
245
+		}
246
+
247
+		// Set output
248
+		for (var row = 0; row < AES._blocksize; row++) {
249
+			for (var col = 0; col < 4; col++)
250
+				m[offset + col * 4 + row] = state[row][col];
251
+		}
252
+
253
+	},
254
+
255
+	_decryptblock: function (c, offset) {
256
+
257
+		// Set input
258
+		for (var row = 0; row < AES._blocksize; row++) {
259
+			for (var col = 0; col < 4; col++)
260
+				state[row][col] = c[offset + col * 4 + row];
261
+		}
262
+
263
+		// Add round key
264
+		for (var row = 0; row < 4; row++) {
265
+			for (var col = 0; col < 4; col++)
266
+				state[row][col] ^= keyschedule[nrounds * 4 + col][row];
267
+		}
268
+
269
+		for (var round = 1; round < nrounds; round++) {
270
+
271
+			// Inv shift rows
272
+			state[1].unshift(state[1].pop());
273
+			state[2].push(state[2].shift());
274
+			state[2].push(state[2].shift());
275
+			state[3].push(state[3].shift());
276
+
277
+			// Inv sub bytes
278
+			for (var row = 0; row < 4; row++) {
279
+				for (var col = 0; col < 4; col++)
280
+					state[row][col] = INVSBOX[state[row][col]];
281
+			}
282
+
283
+			// Add round key
284
+			for (var row = 0; row < 4; row++) {
285
+				for (var col = 0; col < 4; col++)
286
+					state[row][col] ^= keyschedule[(nrounds - round) * 4 + col][row];
287
+			}
288
+
289
+			// Inv mix columns
290
+			for (var col = 0; col < 4; col++) {
291
+
292
+				var s0 = state[0][col],
293
+				    s1 = state[1][col],
294
+				    s2 = state[2][col],
295
+				    s3 = state[3][col];
296
+
297
+				state[0][col] = MULTE[s0] ^ MULTB[s1] ^ MULTD[s2] ^ MULT9[s3];
298
+				state[1][col] = MULT9[s0] ^ MULTE[s1] ^ MULTB[s2] ^ MULTD[s3];
299
+				state[2][col] = MULTD[s0] ^ MULT9[s1] ^ MULTE[s2] ^ MULTB[s3];
300
+				state[3][col] = MULTB[s0] ^ MULTD[s1] ^ MULT9[s2] ^ MULTE[s3];
301
+
302
+			}
303
+
304
+		}
305
+
306
+		// Inv shift rows
307
+		state[1].unshift(state[1].pop());
308
+		state[2].push(state[2].shift());
309
+		state[2].push(state[2].shift());
310
+		state[3].push(state[3].shift());
311
+
312
+		// Inv sub bytes
313
+		for (var row = 0; row < 4; row++) {
314
+			for (var col = 0; col < 4; col++)
315
+				state[row][col] = INVSBOX[state[row][col]];
316
+		}
317
+
318
+		// Add round key
319
+		for (var row = 0; row < 4; row++) {
320
+			for (var col = 0; col < 4; col++)
321
+				state[row][col] ^= keyschedule[col][row];
322
+		}
323
+
324
+		// Set output
325
+		for (var row = 0; row < AES._blocksize; row++) {
326
+			for (var col = 0; col < 4; col++)
327
+				c[offset + col * 4 + row] = state[row][col];
328
+		}
329
+
330
+	},
331
+
332
+
333
+	/**
334
+	 * Private methods
335
+	 */
336
+
337
+	_init: function (k) {
338
+		keylength = k.length / 4;
339
+		nrounds = keylength + 6;
340
+		AES._keyexpansion(k);
341
+	},
342
+
343
+	// Generate a key schedule
344
+	_keyexpansion: function (k) {
345
+
346
+		keyschedule = [];
347
+
348
+		for (var row = 0; row < keylength; row++) {
349
+			keyschedule[row] = [
350
+				k[row * 4],
351
+				k[row * 4 + 1],
352
+				k[row * 4 + 2],
353
+				k[row * 4 + 3]
354
+			];
355
+		}
356
+
357
+		for (var row = keylength; row < AES._blocksize * (nrounds + 1); row++) {
358
+
359
+			var temp = [
360
+				keyschedule[row - 1][0],
361
+				keyschedule[row - 1][1],
362
+				keyschedule[row - 1][2],
363
+				keyschedule[row - 1][3]
364
+			];
365
+
366
+			if (row % keylength == 0) {
367
+
368
+				// Rot word
369
+				temp.push(temp.shift());
370
+
371
+				// Sub word
372
+				temp[0] = SBOX[temp[0]];
373
+				temp[1] = SBOX[temp[1]];
374
+				temp[2] = SBOX[temp[2]];
375
+				temp[3] = SBOX[temp[3]];
376
+
377
+				temp[0] ^= RCON[row / keylength];
378
+
379
+			} else if (keylength > 6 && row % keylength == 4) {
380
+
381
+				// Sub word
382
+				temp[0] = SBOX[temp[0]];
383
+				temp[1] = SBOX[temp[1]];
384
+				temp[2] = SBOX[temp[2]];
385
+				temp[3] = SBOX[temp[3]];
386
+
387
+			}
388
+
389
+			keyschedule[row] = [
390
+				keyschedule[row - keylength][0] ^ temp[0],
391
+				keyschedule[row - keylength][1] ^ temp[1],
392
+				keyschedule[row - keylength][2] ^ temp[2],
393
+				keyschedule[row - keylength][3] ^ temp[3]
394
+			];
395
+
396
+		}
397
+
398
+	}
399
+
400
+};
401
+
402
+})();

+ 378 - 378
utils/lib/BlockModes.js

@@ -1,378 +1,378 @@
1
-/*!
2
- * Crypto-JS contribution from Simon Greatrix
3
- */
4
-
5
-(function(){
6
-
7
-var C = (typeof window === 'undefined') ? require('./Crypto').Crypto : window.Crypto;
8
-
9
-// Create pad namespace
10
-var C_pad = C.pad = {};
11
-
12
-// Calculate the number of padding bytes required.
13
-function _requiredPadding(cipher, message) {
14
-    var blockSizeInBytes = cipher._blocksize * 4;
15
-    var reqd = blockSizeInBytes - message.length % blockSizeInBytes;
16
-    return reqd;
17
-};
18
-
19
-// Remove padding when the final byte gives the number of padding bytes.
20
-var _unpadLength = function (message) {
21
-        var pad = message.pop();
22
-        for (var i = 1; i < pad; i++) {
23
-            message.pop();
24
-        }
25
-    };
26
-
27
-// No-operation padding, used for stream ciphers
28
-C_pad.NoPadding = {
29
-        pad : function (cipher,message) {},
30
-        unpad : function (message) {}
31
-    };
32
-
33
-// Zero Padding.
34
-//
35
-// If the message is not an exact number of blocks, the final block is
36
-// completed with 0x00 bytes. There is no unpadding.
37
-C_pad.ZeroPadding = {
38
-    pad : function (cipher, message) {
39
-        var blockSizeInBytes = cipher._blocksize * 4;
40
-        var reqd = message.length % blockSizeInBytes;
41
-        if( reqd!=0 ) {
42
-            for(reqd = blockSizeInBytes - reqd; reqd>0; reqd--) {
43
-                message.push(0x00);
44
-            }
45
-        }
46
-    },
47
-
48
-    unpad : function (message) {}
49
-};
50
-
51
-// ISO/IEC 7816-4 padding.
52
-//
53
-// Pads the plain text with an 0x80 byte followed by as many 0x00
54
-// bytes are required to complete the block.
55
-C_pad.iso7816 = {
56
-    pad : function (cipher, message) {
57
-        var reqd = _requiredPadding(cipher, message);
58
-        message.push(0x80);
59
-        for (; reqd > 1; reqd--) {
60
-            message.push(0x00);
61
-        }
62
-    },
63
-
64
-    unpad : function (message) {
65
-        while (message.pop() != 0x80) {}
66
-    }
67
-};
68
-
69
-// ANSI X.923 padding
70
-//
71
-// The final block is padded with zeros except for the last byte of the
72
-// last block which contains the number of padding bytes.
73
-C_pad.ansix923 = {
74
-    pad : function (cipher, message) {
75
-        var reqd = _requiredPadding(cipher, message);
76
-        for (var i = 1; i < reqd; i++) {
77
-            message.push(0x00);
78
-        }
79
-        message.push(reqd);
80
-    },
81
-
82
-    unpad : _unpadLength
83
-};
84
-
85
-// ISO 10126
86
-//
87
-// The final block is padded with random bytes except for the last
88
-// byte of the last block which contains the number of padding bytes.
89
-C_pad.iso10126 = {
90
-    pad : function (cipher, message) {
91
-        var reqd = _requiredPadding(cipher, message);
92
-        for (var i = 1; i < reqd; i++) {
93
-            message.push(Math.floor(Math.random() * 256));
94
-        }
95
-        message.push(reqd);
96
-    },
97
-
98
-    unpad : _unpadLength
99
-};
100
-
101
-// PKCS7 padding
102
-//
103
-// PKCS7 is described in RFC 5652. Padding is in whole bytes. The
104
-// value of each added byte is the number of bytes that are added,
105
-// i.e. N bytes, each of value N are added.
106
-C_pad.pkcs7 = {
107
-    pad : function (cipher, message) {
108
-        var reqd = _requiredPadding(cipher, message);
109
-        for (var i = 0; i < reqd; i++) {
110
-            message.push(reqd);
111
-        }
112
-    },
113
-
114
-    unpad : _unpadLength
115
-};
116
-
117
-// Create mode namespace
118
-var C_mode = C.mode = {};
119
-
120
-/**
121
- * Mode base "class".
122
- */
123
-var Mode = C_mode.Mode = function (padding) {
124
-    if (padding) {
125
-        this._padding = padding;
126
-    }
127
-};
128
-
129
-Mode.prototype = {
130
-    encrypt: function (cipher, m, iv) {
131
-        this._padding.pad(cipher, m);
132
-        this._doEncrypt(cipher, m, iv);
133
-    },
134
-
135
-    decrypt: function (cipher, m, iv) {
136
-        this._doDecrypt(cipher, m, iv);
137
-        this._padding.unpad(m);
138
-    },
139
-
140
-    // Default padding
141
-    _padding: C_pad.iso7816
142
-};
143
-
144
-
145
-/**
146
- * Electronic Code Book mode.
147
- * 
148
- * ECB applies the cipher directly against each block of the input.
149
- * 
150
- * ECB does not require an initialization vector.
151
- */
152
-var ECB = C_mode.ECB = function () {
153
-    // Call parent constructor
154
-    Mode.apply(this, arguments);
155
-};
156
-
157
-// Inherit from Mode
158
-var ECB_prototype = ECB.prototype = new Mode;
159
-
160
-// Concrete steps for Mode template
161
-ECB_prototype._doEncrypt = function (cipher, m, iv) {
162
-    var blockSizeInBytes = cipher._blocksize * 4;
163
-    // Encrypt each block
164
-    for (var offset = 0; offset < m.length; offset += blockSizeInBytes) {
165
-        cipher._encryptblock(m, offset);
166
-    }
167
-};
168
-ECB_prototype._doDecrypt = function (cipher, c, iv) {
169
-    var blockSizeInBytes = cipher._blocksize * 4;
170
-    // Decrypt each block
171
-    for (var offset = 0; offset < c.length; offset += blockSizeInBytes) {
172
-        cipher._decryptblock(c, offset);
173
-    }
174
-};
175
-
176
-// ECB never uses an IV
177
-ECB_prototype.fixOptions = function (options) {
178
-    options.iv = [];
179
-};
180
-
181
-
182
-/**
183
- * Cipher block chaining
184
- * 
185
- * The first block is XORed with the IV. Subsequent blocks are XOR with the
186
- * previous cipher output.
187
- */
188
-var CBC = C_mode.CBC = function () {
189
-    // Call parent constructor
190
-    Mode.apply(this, arguments);
191
-};
192
-
193
-// Inherit from Mode
194
-var CBC_prototype = CBC.prototype = new Mode;
195
-
196
-// Concrete steps for Mode template
197
-CBC_prototype._doEncrypt = function (cipher, m, iv) {
198
-    var blockSizeInBytes = cipher._blocksize * 4;
199
-
200
-    // Encrypt each block
201
-    for (var offset = 0; offset < m.length; offset += blockSizeInBytes) {
202
-        if (offset == 0) {
203
-            // XOR first block using IV
204
-            for (var i = 0; i < blockSizeInBytes; i++)
205
-            m[i] ^= iv[i];
206
-        } else {
207
-            // XOR this block using previous crypted block
208
-            for (var i = 0; i < blockSizeInBytes; i++)
209
-            m[offset + i] ^= m[offset + i - blockSizeInBytes];
210
-        }
211
-        // Encrypt block
212
-        cipher._encryptblock(m, offset);
213
-    }
214
-};
215
-CBC_prototype._doDecrypt = function (cipher, c, iv) {
216
-    var blockSizeInBytes = cipher._blocksize * 4;
217
-
218
-    // At the start, the previously crypted block is the IV
219
-    var prevCryptedBlock = iv;
220
-
221
-    // Decrypt each block
222
-    for (var offset = 0; offset < c.length; offset += blockSizeInBytes) {
223
-        // Save this crypted block
224
-        var thisCryptedBlock = c.slice(offset, offset + blockSizeInBytes);
225
-        // Decrypt block
226
-        cipher._decryptblock(c, offset);
227
-        // XOR decrypted block using previous crypted block
228
-        for (var i = 0; i < blockSizeInBytes; i++) {
229
-            c[offset + i] ^= prevCryptedBlock[i];
230
-        }
231
-        prevCryptedBlock = thisCryptedBlock;
232
-    }
233
-};
234
-
235
-
236
-/**
237
- * Cipher feed back
238
- * 
239
- * The cipher output is XORed with the plain text to produce the cipher output,
240
- * which is then fed back into the cipher to produce a bit pattern to XOR the
241
- * next block with.
242
- * 
243
- * This is a stream cipher mode and does not require padding.
244
- */
245
-var CFB = C_mode.CFB = function () {
246
-    // Call parent constructor
247
-    Mode.apply(this, arguments);
248
-};
249
-
250
-// Inherit from Mode
251
-var CFB_prototype = CFB.prototype = new Mode;
252
-
253
-// Override padding
254
-CFB_prototype._padding = C_pad.NoPadding;
255
-
256
-// Concrete steps for Mode template
257
-CFB_prototype._doEncrypt = function (cipher, m, iv) {
258
-    var blockSizeInBytes = cipher._blocksize * 4,
259
-        keystream = iv.slice(0);
260
-
261
-    // Encrypt each byte
262
-    for (var i = 0; i < m.length; i++) {
263
-
264
-        var j = i % blockSizeInBytes;
265
-        if (j == 0) cipher._encryptblock(keystream, 0);
266
-
267
-        m[i] ^= keystream[j];
268
-        keystream[j] = m[i];
269
-    }
270
-};
271
-CFB_prototype._doDecrypt = function (cipher, c, iv) {
272
-    var blockSizeInBytes = cipher._blocksize * 4,
273
-        keystream = iv.slice(0);
274
-
275
-    // Encrypt each byte
276
-    for (var i = 0; i < c.length; i++) {
277
-
278
-        var j = i % blockSizeInBytes;
279
-        if (j == 0) cipher._encryptblock(keystream, 0);
280
-
281
-        var b = c[i];
282
-        c[i] ^= keystream[j];
283
-        keystream[j] = b;
284
-    }
285
-};
286
-
287
-
288
-/**
289
- * Output feed back
290
- * 
291
- * The cipher repeatedly encrypts its own output. The output is XORed with the
292
- * plain text to produce the cipher text.
293
- * 
294
- * This is a stream cipher mode and does not require padding.
295
- */
296
-var OFB = C_mode.OFB = function () {
297
-    // Call parent constructor
298
-    Mode.apply(this, arguments);
299
-};
300
-
301
-// Inherit from Mode
302
-var OFB_prototype = OFB.prototype = new Mode;
303
-
304
-// Override padding
305
-OFB_prototype._padding = C_pad.NoPadding;
306
-
307
-// Concrete steps for Mode template
308
-OFB_prototype._doEncrypt = function (cipher, m, iv) {
309
-
310
-    var blockSizeInBytes = cipher._blocksize * 4,
311
-        keystream = iv.slice(0);
312
-
313
-    // Encrypt each byte
314
-    for (var i = 0; i < m.length; i++) {
315
-
316
-        // Generate keystream
317
-        if (i % blockSizeInBytes == 0)
318
-            cipher._encryptblock(keystream, 0);
319
-
320
-        // Encrypt byte
321
-        m[i] ^= keystream[i % blockSizeInBytes];
322
-
323
-    }
324
-};
325
-OFB_prototype._doDecrypt = OFB_prototype._doEncrypt;
326
-
327
-/**
328
- * Counter
329
- * @author Gergely Risko
330
- *
331
- * After every block the last 4 bytes of the IV is increased by one
332
- * with carry and that IV is used for the next block.
333
- *
334
- * This is a stream cipher mode and does not require padding.
335
- */
336
-var CTR = C_mode.CTR = function () {
337
-    // Call parent constructor
338
-    Mode.apply(this, arguments);
339
-};
340
-
341
-// Inherit from Mode
342
-var CTR_prototype = CTR.prototype = new Mode;
343
-
344
-// Override padding
345
-CTR_prototype._padding = C_pad.NoPadding;
346
-
347
-CTR_prototype._doEncrypt = function (cipher, m, iv) {
348
-    var blockSizeInBytes = cipher._blocksize * 4;
349
-    var counter = iv.slice(0);
350
-
351
-    for (var i = 0; i < m.length;) {
352
-        // do not lose iv
353
-        var keystream = counter.slice(0);
354
-
355
-        // Generate keystream for next block
356
-        cipher._encryptblock(keystream, 0);
357
-
358
-        // XOR keystream with block
359
-        for (var j = 0; i < m.length && j < blockSizeInBytes; j++, i++) {
360
-            m[i] ^= keystream[j];
361
-        }
362
-
363
-        // Increase counter
364
-        if(++(counter[blockSizeInBytes-1]) == 256) {
365
-            counter[blockSizeInBytes-1] = 0;
366
-            if(++(counter[blockSizeInBytes-2]) == 256) {
367
-                counter[blockSizeInBytes-2] = 0;
368
-                if(++(counter[blockSizeInBytes-3]) == 256) {
369
-                    counter[blockSizeInBytes-3] = 0;
370
-                    ++(counter[blockSizeInBytes-4]);
371
-                }
372
-            }
373
-        }
374
-    }
375
-};
376
-CTR_prototype._doDecrypt = CTR_prototype._doEncrypt;
377
-
378
-})();
1
+/*!
2
+ * Crypto-JS contribution from Simon Greatrix
3
+ */
4
+
5
+(function(){
6
+
7
+var C = (typeof window === 'undefined') ? require('./Crypto').Crypto : window.Crypto;
8
+
9
+// Create pad namespace
10
+var C_pad = C.pad = {};
11
+
12
+// Calculate the number of padding bytes required.
13
+function _requiredPadding(cipher, message) {
14
+    var blockSizeInBytes = cipher._blocksize * 4;
15
+    var reqd = blockSizeInBytes - message.length % blockSizeInBytes;
16
+    return reqd;
17
+};
18
+
19
+// Remove padding when the final byte gives the number of padding bytes.
20
+var _unpadLength = function (message) {
21
+        var pad = message.pop();
22
+        for (var i = 1; i < pad; i++) {
23
+            message.pop();
24
+        }
25
+    };
26
+
27
+// No-operation padding, used for stream ciphers
28
+C_pad.NoPadding = {
29
+        pad : function (cipher,message) {},
30
+        unpad : function (message) {}
31
+    };
32
+
33
+// Zero Padding.
34
+//
35
+// If the message is not an exact number of blocks, the final block is
36
+// completed with 0x00 bytes. There is no unpadding.
37
+C_pad.ZeroPadding = {
38
+    pad : function (cipher, message) {
39
+        var blockSizeInBytes = cipher._blocksize * 4;
40
+        var reqd = message.length % blockSizeInBytes;
41
+        if( reqd!=0 ) {
42
+            for(reqd = blockSizeInBytes - reqd; reqd>0; reqd--) {
43
+                message.push(0x00);
44
+            }
45
+        }
46
+    },
47
+
48
+    unpad : function (message) {}
49
+};
50
+
51
+// ISO/IEC 7816-4 padding.
52
+//
53
+// Pads the plain text with an 0x80 byte followed by as many 0x00
54
+// bytes are required to complete the block.
55
+C_pad.iso7816 = {
56
+    pad : function (cipher, message) {
57
+        var reqd = _requiredPadding(cipher, message);
58
+        message.push(0x80);
59
+        for (; reqd > 1; reqd--) {
60
+            message.push(0x00);
61
+        }
62
+    },
63
+
64
+    unpad : function (message) {
65
+        while (message.pop() != 0x80) {}
66
+    }
67
+};
68
+
69
+// ANSI X.923 padding
70
+//
71
+// The final block is padded with zeros except for the last byte of the
72
+// last block which contains the number of padding bytes.
73
+C_pad.ansix923 = {
74
+    pad : function (cipher, message) {
75
+        var reqd = _requiredPadding(cipher, message);
76
+        for (var i = 1; i < reqd; i++) {
77
+            message.push(0x00);
78
+        }
79
+        message.push(reqd);
80
+    },
81
+
82
+    unpad : _unpadLength
83
+};
84
+
85
+// ISO 10126
86
+//
87
+// The final block is padded with random bytes except for the last
88
+// byte of the last block which contains the number of padding bytes.
89
+C_pad.iso10126 = {
90
+    pad : function (cipher, message) {
91
+        var reqd = _requiredPadding(cipher, message);
92
+        for (var i = 1; i < reqd; i++) {
93
+            message.push(Math.floor(Math.random() * 256));
94
+        }
95
+        message.push(reqd);
96
+    },
97
+
98
+    unpad : _unpadLength
99
+};
100
+
101
+// PKCS7 padding
102
+//
103
+// PKCS7 is described in RFC 5652. Padding is in whole bytes. The
104
+// value of each added byte is the number of bytes that are added,
105
+// i.e. N bytes, each of value N are added.
106
+C_pad.pkcs7 = {
107
+    pad : function (cipher, message) {
108
+        var reqd = _requiredPadding(cipher, message);
109
+        for (var i = 0; i < reqd; i++) {
110
+            message.push(reqd);
111
+        }
112
+    },
113
+
114
+    unpad : _unpadLength
115
+};
116
+
117
+// Create mode namespace
118
+var C_mode = C.mode = {};
119
+
120
+/**
121
+ * Mode base "class".
122
+ */
123
+var Mode = C_mode.Mode = function (padding) {
124
+    if (padding) {
125
+        this._padding = padding;
126
+    }
127
+};
128
+
129
+Mode.prototype = {
130
+    encrypt: function (cipher, m, iv) {
131
+        this._padding.pad(cipher, m);
132
+        this._doEncrypt(cipher, m, iv);
133
+    },
134
+
135
+    decrypt: function (cipher, m, iv) {
136
+        this._doDecrypt(cipher, m, iv);
137
+        this._padding.unpad(m);
138
+    },
139
+
140
+    // Default padding
141
+    _padding: C_pad.iso7816
142
+};
143
+
144
+
145
+/**
146
+ * Electronic Code Book mode.
147
+ * 
148
+ * ECB applies the cipher directly against each block of the input.
149
+ * 
150
+ * ECB does not require an initialization vector.
151
+ */
152
+var ECB = C_mode.ECB = function () {
153
+    // Call parent constructor
154
+    Mode.apply(this, arguments);
155
+};
156
+
157
+// Inherit from Mode
158
+var ECB_prototype = ECB.prototype = new Mode;
159
+
160
+// Concrete steps for Mode template
161
+ECB_prototype._doEncrypt = function (cipher, m, iv) {
162
+    var blockSizeInBytes = cipher._blocksize * 4;
163
+    // Encrypt each block
164
+    for (var offset = 0; offset < m.length; offset += blockSizeInBytes) {
165
+        cipher._encryptblock(m, offset);
166
+    }
167
+};
168
+ECB_prototype._doDecrypt = function (cipher, c, iv) {
169
+    var blockSizeInBytes = cipher._blocksize * 4;
170
+    // Decrypt each block
171
+    for (var offset = 0; offset < c.length; offset += blockSizeInBytes) {
172
+        cipher._decryptblock(c, offset);
173
+    }
174
+};
175
+
176
+// ECB never uses an IV
177
+ECB_prototype.fixOptions = function (options) {
178
+    options.iv = [];
179
+};
180
+
181
+
182
+/**
183
+ * Cipher block chaining
184
+ * 
185
+ * The first block is XORed with the IV. Subsequent blocks are XOR with the
186
+ * previous cipher output.
187
+ */
188
+var CBC = C_mode.CBC = function () {
189
+    // Call parent constructor
190
+    Mode.apply(this, arguments);
191
+};
192
+
193
+// Inherit from Mode
194
+var CBC_prototype = CBC.prototype = new Mode;
195
+
196
+// Concrete steps for Mode template
197
+CBC_prototype._doEncrypt = function (cipher, m, iv) {
198
+    var blockSizeInBytes = cipher._blocksize * 4;
199
+
200
+    // Encrypt each block
201
+    for (var offset = 0; offset < m.length; offset += blockSizeInBytes) {
202
+        if (offset == 0) {
203
+            // XOR first block using IV
204
+            for (var i = 0; i < blockSizeInBytes; i++)
205
+            m[i] ^= iv[i];
206
+        } else {
207
+            // XOR this block using previous crypted block
208
+            for (var i = 0; i < blockSizeInBytes; i++)
209
+            m[offset + i] ^= m[offset + i - blockSizeInBytes];
210
+        }
211
+        // Encrypt block
212
+        cipher._encryptblock(m, offset);
213
+    }
214
+};
215
+CBC_prototype._doDecrypt = function (cipher, c, iv) {
216
+    var blockSizeInBytes = cipher._blocksize * 4;
217
+
218
+    // At the start, the previously crypted block is the IV
219
+    var prevCryptedBlock = iv;
220
+
221
+    // Decrypt each block
222
+    for (var offset = 0; offset < c.length; offset += blockSizeInBytes) {
223
+        // Save this crypted block
224
+        var thisCryptedBlock = c.slice(offset, offset + blockSizeInBytes);
225
+        // Decrypt block
226
+        cipher._decryptblock(c, offset);
227
+        // XOR decrypted block using previous crypted block
228
+        for (var i = 0; i < blockSizeInBytes; i++) {
229
+            c[offset + i] ^= prevCryptedBlock[i];
230
+        }
231
+        prevCryptedBlock = thisCryptedBlock;
232
+    }
233
+};
234
+
235
+
236
+/**
237
+ * Cipher feed back
238
+ * 
239
+ * The cipher output is XORed with the plain text to produce the cipher output,
240
+ * which is then fed back into the cipher to produce a bit pattern to XOR the
241
+ * next block with.
242
+ * 
243
+ * This is a stream cipher mode and does not require padding.
244
+ */
245
+var CFB = C_mode.CFB = function () {
246
+    // Call parent constructor
247
+    Mode.apply(this, arguments);
248
+};
249
+
250
+// Inherit from Mode
251
+var CFB_prototype = CFB.prototype = new Mode;
252
+
253
+// Override padding
254
+CFB_prototype._padding = C_pad.NoPadding;
255
+
256
+// Concrete steps for Mode template
257
+CFB_prototype._doEncrypt = function (cipher, m, iv) {
258
+    var blockSizeInBytes = cipher._blocksize * 4,
259
+        keystream = iv.slice(0);
260
+
261
+    // Encrypt each byte
262
+    for (var i = 0; i < m.length; i++) {
263
+
264
+        var j = i % blockSizeInBytes;
265
+        if (j == 0) cipher._encryptblock(keystream, 0);
266
+
267
+        m[i] ^= keystream[j];
268
+        keystream[j] = m[i];
269
+    }
270
+};
271
+CFB_prototype._doDecrypt = function (cipher, c, iv) {
272
+    var blockSizeInBytes = cipher._blocksize * 4,
273
+        keystream = iv.slice(0);
274
+
275
+    // Encrypt each byte
276
+    for (var i = 0; i < c.length; i++) {
277
+
278
+        var j = i % blockSizeInBytes;
279
+        if (j == 0) cipher._encryptblock(keystream, 0);
280
+
281
+        var b = c[i];
282
+        c[i] ^= keystream[j];
283
+        keystream[j] = b;
284
+    }
285
+};
286
+
287
+
288
+/**
289
+ * Output feed back
290
+ * 
291
+ * The cipher repeatedly encrypts its own output. The output is XORed with the
292
+ * plain text to produce the cipher text.
293
+ * 
294
+ * This is a stream cipher mode and does not require padding.
295
+ */
296
+var OFB = C_mode.OFB = function () {
297
+    // Call parent constructor
298
+    Mode.apply(this, arguments);
299
+};
300
+
301
+// Inherit from Mode
302
+var OFB_prototype = OFB.prototype = new Mode;
303
+
304
+// Override padding
305
+OFB_prototype._padding = C_pad.NoPadding;
306
+
307
+// Concrete steps for Mode template
308
+OFB_prototype._doEncrypt = function (cipher, m, iv) {
309
+
310
+    var blockSizeInBytes = cipher._blocksize * 4,
311
+        keystream = iv.slice(0);
312
+
313
+    // Encrypt each byte
314
+    for (var i = 0; i < m.length; i++) {
315
+
316
+        // Generate keystream
317
+        if (i % blockSizeInBytes == 0)
318
+            cipher._encryptblock(keystream, 0);
319
+
320
+        // Encrypt byte
321
+        m[i] ^= keystream[i % blockSizeInBytes];
322
+
323
+    }
324
+};
325
+OFB_prototype._doDecrypt = OFB_prototype._doEncrypt;
326
+
327
+/**
328
+ * Counter
329
+ * @author Gergely Risko
330
+ *
331
+ * After every block the last 4 bytes of the IV is increased by one
332
+ * with carry and that IV is used for the next block.
333
+ *
334
+ * This is a stream cipher mode and does not require padding.
335
+ */
336
+var CTR = C_mode.CTR = function () {
337
+    // Call parent constructor
338
+    Mode.apply(this, arguments);
339
+};
340
+
341
+// Inherit from Mode
342
+var CTR_prototype = CTR.prototype = new Mode;
343
+
344
+// Override padding
345
+CTR_prototype._padding = C_pad.NoPadding;
346
+
347
+CTR_prototype._doEncrypt = function (cipher, m, iv) {
348
+    var blockSizeInBytes = cipher._blocksize * 4;
349
+    var counter = iv.slice(0);
350
+
351
+    for (var i = 0; i < m.length;) {
352
+        // do not lose iv
353
+        var keystream = counter.slice(0);
354
+
355
+        // Generate keystream for next block
356
+        cipher._encryptblock(keystream, 0);
357
+
358
+        // XOR keystream with block
359
+        for (var j = 0; i < m.length && j < blockSizeInBytes; j++, i++) {
360
+            m[i] ^= keystream[j];
361
+        }
362
+
363
+        // Increase counter
364
+        if(++(counter[blockSizeInBytes-1]) == 256) {
365
+            counter[blockSizeInBytes-1] = 0;
366
+            if(++(counter[blockSizeInBytes-2]) == 256) {
367
+                counter[blockSizeInBytes-2] = 0;
368
+                if(++(counter[blockSizeInBytes-3]) == 256) {
369
+                    counter[blockSizeInBytes-3] = 0;
370
+                    ++(counter[blockSizeInBytes-4]);
371
+                }
372
+            }
373
+        }
374
+    }
375
+};
376
+CTR_prototype._doDecrypt = CTR_prototype._doEncrypt;
377
+
378
+})();

+ 155 - 155
utils/lib/Crypto.js

@@ -1,155 +1,155 @@
1
-if (typeof Crypto == "undefined" || ! Crypto.util)
2
-{
3
-(function(){
4
-
5
-var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
6
-
7
-// Global Crypto object
8
-// with browser window or with node module
9
-var Crypto = (typeof window === 'undefined') ? exports.Crypto = {} : window.Crypto = {}; 
10
-
11
-// Crypto utilities
12
-var util = Crypto.util = {
13
-
14
-	// Bit-wise rotate left
15
-	rotl: function (n, b) {
16
-		return (n << b) | (n >>> (32 - b));
17
-	},
18
-
19
-	// Bit-wise rotate right
20
-	rotr: function (n, b) {
21
-		return (n << (32 - b)) | (n >>> b);
22
-	},
23
-
24
-	// Swap big-endian to little-endian and vice versa
25
-	endian: function (n) {
26
-
27
-		// If number given, swap endian
28
-		if (n.constructor == Number) {
29
-			return util.rotl(n,  8) & 0x00FF00FF |
30
-			       util.rotl(n, 24) & 0xFF00FF00;
31
-		}
32
-
33
-		// Else, assume array and swap all items
34
-		for (var i = 0; i < n.length; i++)
35
-			n[i] = util.endian(n[i]);
36
-		return n;
37
-
38
-	},
39
-
40
-	// Generate an array of any length of random bytes
41
-	randomBytes: function (n) {
42
-		for (var bytes = []; n > 0; n--)
43
-			bytes.push(Math.floor(Math.random() * 256));
44
-		return bytes;
45
-	},
46
-
47
-	// Convert a byte array to big-endian 32-bit words
48
-	bytesToWords: function (bytes) {
49
-		for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
50
-			words[b >>> 5] |= (bytes[i] & 0xFF) << (24 - b % 32);
51
-		return words;
52
-	},
53
-
54
-	// Convert big-endian 32-bit words to a byte array
55
-	wordsToBytes: function (words) {
56
-		for (var bytes = [], b = 0; b < words.length * 32; b += 8)
57
-			bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
58
-		return bytes;
59
-	},
60
-
61
-	// Convert a byte array to a hex string
62
-	bytesToHex: function (bytes) {
63
-		for (var hex = [], i = 0; i < bytes.length; i++) {
64
-			hex.push((bytes[i] >>> 4).toString(16));
65
-			hex.push((bytes[i] & 0xF).toString(16));
66
-		}
67
-		return hex.join("");
68
-	},
69
-
70
-	// Convert a hex string to a byte array
71
-	hexToBytes: function (hex) {
72
-		for (var bytes = [], c = 0; c < hex.length; c += 2)
73
-			bytes.push(parseInt(hex.substr(c, 2), 16));
74
-		return bytes;
75
-	},
76
-
77
-	// Convert a byte array to a base-64 string
78
-	bytesToBase64: function (bytes) {
79
-
80
-		// Use browser-native function if it exists
81
-		if (typeof btoa == "function") return btoa(Binary.bytesToString(bytes));
82
-
83
-		for(var base64 = [], i = 0; i < bytes.length; i += 3) {
84
-			var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
85
-			for (var j = 0; j < 4; j++) {
86
-				if (i * 8 + j * 6 <= bytes.length * 8)
87
-					base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));
88
-				else base64.push("=");
89
-			}
90
-		}
91
-
92
-		return base64.join("");
93
-
94
-	},
95
-
96
-	// Convert a base-64 string to a byte array
97
-	base64ToBytes: function (base64) {
98
-
99
-		// Use browser-native function if it exists
100
-		if (typeof atob == "function") return Binary.stringToBytes(atob(base64));
101
-
102
-		// Remove non-base-64 characters
103
-		base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
104
-
105
-		for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
106
-			if (imod4 == 0) continue;
107
-			bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2)) |
108
-			           (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
109
-		}
110
-
111
-		return bytes;
112
-
113
-	}
114
-
115
-};
116
-
117
-// Crypto character encodings
118
-var charenc = Crypto.charenc = {};
119
-
120
-// UTF-8 encoding
121
-var UTF8 = charenc.UTF8 = {
122
-
123
-	// Convert a string to a byte array
124
-	stringToBytes: function (str) {
125
-		return Binary.stringToBytes(unescape(encodeURIComponent(str)));
126
-	},
127
-
128
-	// Convert a byte array to a string
129
-	bytesToString: function (bytes) {
130
-		return decodeURIComponent(escape(Binary.bytesToString(bytes)));
131
-	}
132
-
133
-};
134
-
135
-// Binary encoding
136
-var Binary = charenc.Binary = {
137
-
138
-	// Convert a string to a byte array
139
-	stringToBytes: function (str) {
140
-		for (var bytes = [], i = 0; i < str.length; i++)
141
-			bytes.push(str.charCodeAt(i) & 0xFF);
142
-		return bytes;
143
-	},
144
-
145
-	// Convert a byte array to a string
146
-	bytesToString: function (bytes) {
147
-		for (var str = [], i = 0; i < bytes.length; i++)
148
-			str.push(String.fromCharCode(bytes[i]));
149
-		return str.join("");
150
-	}
151
-
152
-};
153
-
154
-})();
155
-}
1
+if (typeof Crypto == "undefined" || ! Crypto.util)
2
+{
3
+(function(){
4
+
5
+var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
6
+
7
+// Global Crypto object
8
+// with browser window or with node module
9
+var Crypto = (typeof window === 'undefined') ? exports.Crypto = {} : window.Crypto = {}; 
10
+
11
+// Crypto utilities
12
+var util = Crypto.util = {
13
+
14
+	// Bit-wise rotate left
15
+	rotl: function (n, b) {
16
+		return (n << b) | (n >>> (32 - b));
17
+	},
18
+
19
+	// Bit-wise rotate right
20
+	rotr: function (n, b) {
21
+		return (n << (32 - b)) | (n >>> b);
22
+	},
23
+
24
+	// Swap big-endian to little-endian and vice versa
25
+	endian: function (n) {
26
+
27
+		// If number given, swap endian
28
+		if (n.constructor == Number) {
29
+			return util.rotl(n,  8) & 0x00FF00FF |
30
+			       util.rotl(n, 24) & 0xFF00FF00;
31
+		}
32
+
33
+		// Else, assume array and swap all items
34
+		for (var i = 0; i < n.length; i++)
35
+			n[i] = util.endian(n[i]);
36
+		return n;
37
+
38
+	},
39
+
40
+	// Generate an array of any length of random bytes
41
+	randomBytes: function (n) {
42
+		for (var bytes = []; n > 0; n--)
43
+			bytes.push(Math.floor(Math.random() * 256));
44
+		return bytes;
45
+	},
46
+
47
+	// Convert a byte array to big-endian 32-bit words
48
+	bytesToWords: function (bytes) {
49
+		for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
50
+			words[b >>> 5] |= (bytes[i] & 0xFF) << (24 - b % 32);
51
+		return words;
52
+	},
53
+
54
+	// Convert big-endian 32-bit words to a byte array
55
+	wordsToBytes: function (words) {
56
+		for (var bytes = [], b = 0; b < words.length * 32; b += 8)
57
+			bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
58
+		return bytes;
59
+	},
60
+
61
+	// Convert a byte array to a hex string
62
+	bytesToHex: function (bytes) {
63
+		for (var hex = [], i = 0; i < bytes.length; i++) {
64
+			hex.push((bytes[i] >>> 4).toString(16));
65
+			hex.push((bytes[i] & 0xF).toString(16));
66
+		}
67
+		return hex.join("");
68
+	},
69
+
70
+	// Convert a hex string to a byte array
71
+	hexToBytes: function (hex) {
72
+		for (var bytes = [], c = 0; c < hex.length; c += 2)
73
+			bytes.push(parseInt(hex.substr(c, 2), 16));
74
+		return bytes;
75
+	},
76
+
77
+	// Convert a byte array to a base-64 string
78
+	bytesToBase64: function (bytes) {
79
+
80
+		// Use browser-native function if it exists
81
+		if (typeof btoa == "function") return btoa(Binary.bytesToString(bytes));
82
+
83
+		for(var base64 = [], i = 0; i < bytes.length; i += 3) {
84
+			var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
85
+			for (var j = 0; j < 4; j++) {
86
+				if (i * 8 + j * 6 <= bytes.length * 8)
87
+					base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));
88
+				else base64.push("=");
89
+			}
90
+		}
91
+
92
+		return base64.join("");
93
+
94
+	},
95
+
96
+	// Convert a base-64 string to a byte array
97
+	base64ToBytes: function (base64) {
98
+
99
+		// Use browser-native function if it exists
100
+		if (typeof atob == "function") return Binary.stringToBytes(atob(base64));
101
+
102
+		// Remove non-base-64 characters
103
+		base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
104
+
105
+		for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
106
+			if (imod4 == 0) continue;
107
+			bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2)) |
108
+			           (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
109
+		}
110
+
111
+		return bytes;
112
+
113
+	}
114
+
115
+};
116
+
117
+// Crypto character encodings
118
+var charenc = Crypto.charenc = {};
119
+
120
+// UTF-8 encoding
121
+var UTF8 = charenc.UTF8 = {
122
+
123
+	// Convert a string to a byte array
124
+	stringToBytes: function (str) {
125
+		return Binary.stringToBytes(unescape(encodeURIComponent(str)));
126
+	},
127
+
128
+	// Convert a byte array to a string
129
+	bytesToString: function (bytes) {
130
+		return decodeURIComponent(escape(Binary.bytesToString(bytes)));
131
+	}
132
+
133
+};
134
+
135
+// Binary encoding
136
+var Binary = charenc.Binary = {
137
+
138
+	// Convert a string to a byte array
139
+	stringToBytes: function (str) {
140
+		for (var bytes = [], i = 0; i < str.length; i++)
141
+			bytes.push(str.charCodeAt(i) & 0xFF);
142
+		return bytes;
143
+	},
144
+
145
+	// Convert a byte array to a string
146
+	bytesToString: function (bytes) {
147
+		for (var str = [], i = 0; i < bytes.length; i++)
148
+			str.push(String.fromCharCode(bytes[i]));
149
+		return str.join("");
150
+	}
151
+
152
+};
153
+
154
+})();
155
+}

+ 2 - 2
utils/main.js

@@ -2,7 +2,7 @@ import common from '../utils/util';
2 2
 var app = getApp();
3 3
 
4 4
 function getData(url, callback) {
5
-  //console.log("加密前的结果为===", url);
5
+  console.log("加密前的结果为===", url);
6 6
   var url = common.Encrypt(url);
7 7
   //console.log("加密后的结果为===",url);
8 8
   wx.request({
@@ -23,7 +23,7 @@ function getData(url, callback) {
23 23
 
24 24
 function postData(url, postData, callback) {
25 25
   var url = common.Encrypt(url);
26
-  //console.log("加密后的结果为===",url);
26
+  console.log("加密后的结果为===",url);
27 27
   wx.request({
28 28
     url: app.globalData.serverUrl + url,
29 29
     method: "POST",