Skip to content

Commit 605a8a2

Browse files
[fix]提供隧道加密和解密工具方法 review by songym
1 parent 6520af5 commit 605a8a2

File tree

6 files changed

+68
-10
lines changed

6 files changed

+68
-10
lines changed

src/common/index.common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ import {
324324
FilterField,
325325
OnlineServiceBase
326326
} from './online';
327-
import { KeyServiceParameter, SecurityManager, ServerInfo, TokenServiceParameter } from './security';
327+
import { KeyServiceParameter, SecurityManager, ServerInfo, TokenServiceParameter, decrypt } from './security';
328328
import { ElasticSearch } from './thirdparty';
329329
import {
330330
isCORS,
@@ -745,7 +745,7 @@ export {
745745
FeatureTheme,
746746
Transform
747747
};
748-
export { KeyServiceParameter, SecurityManager, ServerInfo, TokenServiceParameter };
748+
export { KeyServiceParameter, SecurityManager, ServerInfo, TokenServiceParameter, decrypt };
749749
export { CartoCSS, ThemeStyle };
750750
export { ElasticSearch };
751751
export { Lang };

src/common/namespace.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ import {
326326
FilterField,
327327
OnlineServiceBase,
328328
KeyServiceParameter,
329+
decrypt,
329330
SecurityManager,
330331
ServerInfo,
331332
TokenServiceParameter,
@@ -890,6 +891,7 @@ SuperMap.KeyServiceParameter = KeyServiceParameter;
890891
SuperMap.SecurityManager = SecurityManager;
891892
SuperMap.ServerInfo = ServerInfo;
892893
SuperMap.TokenServiceParameter = TokenServiceParameter;
894+
SuperMap.decrypt= decrypt;
893895
// style
894896
SuperMap.ThemeStyle = ThemeStyle;
895897
SuperMap.CartoCSS = CartoCSS;

src/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@antv/g2": "^4.2.11",
1818
"@antv/g6": "^4.8.14",
19+
"@supermapgis/tile-decryptor": "^1.0.0",
1920
"@turf/meta": "^6.5.0",
2021
"echarts": "5.5.0",
2122
"fast-xml-parser": "^4.2.7",

src/common/security/decrypt.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
2+
* This program are made available under the terms of the Apache License, Version 2.0
3+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4+
import decryptUtil from '@supermapgis/tile-decryptor';
5+
6+
/**
7+
* @category Security
8+
* @function decrypt
9+
* @description 隧道解密ArrayBuffer数据。
10+
* @param {Object} options - 参数。
11+
* @param {ArrayBuffer} options.arrayBuffer - 解密数据,数据格式为ArrayBuffer。
12+
* @param {string} options.key - 秘钥
13+
* @param {string} options.algorithm - 加密算法, 可选值: "AES"、"AES/CTR"、"SM4"、"SM4/CTR"。
14+
* @param {number} [options.decodeSize=256] - 需要解密的数据大小。
15+
* @param {Array<number>} [options.ivKey] - 当algorithm为'AES'或者"AES/CTR", 默认值为:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];当algorithm为'SM4'或者"SM4/CTR", 默认值为:[48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102]。
16+
* @returns {string} 解密后的数据。
17+
* @usage
18+
* ```
19+
* // 浏览器
20+
* <script type="text/javascript" src="{cdn}"></script>
21+
* <script>
22+
* const result = {namespace}.decrypt(options);
23+
*
24+
* </script>
25+
*
26+
* // ES6 Import
27+
* import { decrypt } from '{npm}';
28+
*
29+
* const result = decrypt(options);
30+
* ```
31+
*/
32+
const decrypt = (options) => {
33+
const res = decryptUtil({ ...options });
34+
const decoder = new TextDecoder();
35+
const decodeStr = decoder.decode(new Uint8Array(res));
36+
return decodeStr;
37+
};
38+
39+
export { decrypt };

src/common/security/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4-
import {KeyServiceParameter} from './KeyServiceParameter';
5-
import {SecurityManager} from './SecurityManager';
6-
import {ServerInfo} from './ServerInfo';
7-
import {TokenServiceParameter} from './TokenServiceParameter';
4+
import { KeyServiceParameter } from './KeyServiceParameter';
5+
import { SecurityManager } from './SecurityManager';
6+
import { ServerInfo } from './ServerInfo';
7+
import { TokenServiceParameter } from './TokenServiceParameter';
8+
import { decrypt } from './decrypt';
89

9-
export {KeyServiceParameter} ;
10-
export {SecurityManager} ;
11-
export {ServerInfo} ;
12-
export {TokenServiceParameter} ;
10+
export { KeyServiceParameter };
11+
export { SecurityManager };
12+
export { ServerInfo };
13+
export { TokenServiceParameter };
14+
export { decrypt };
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { decrypt } from '../../../src/common/security/decrypt';
2+
3+
describe('decrypt', () => {
4+
it('decrypt AFS', () => {
5+
const unit8 = Uint8Array.from([65, 254, 189, 210, 176, 155, 38, 120, 236, 244]);
6+
var options = {
7+
arrayBuffer: unit8.buffer,
8+
key: 'nSDXTzVXy93lc4dmhokTyWvMbiAroF8cSmIfulJG9bg=',
9+
algorithm: 'AES'
10+
};
11+
var parameter = decrypt(options);
12+
expect(parameter).toEqual('{"recordse');
13+
});
14+
});

0 commit comments

Comments
 (0)