mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Removed padding characters from all base64 encoded strings.
Removed RegExp that trims padding characters from `base64` encoded strings from `atob` code helper to prevent mutation of `RegExp.$1` value during calls to the `stringArray`. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/829
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v2.10.1
|
||||
---
|
||||
* Removed padding characters from all base64 encoded strings. Removed RegExp that trims padding characters from `base64` encoded strings from `atob` code helper to prevent mutation of `RegExp.$1` value during calls to the `stringArray`. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/829
|
||||
|
||||
v2.10.0
|
||||
---
|
||||
* Improved `rotateStringArray` option
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "2.10.0",
|
||||
"version": "2.10.1",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
@@ -86,7 +86,7 @@
|
||||
"ts-node": "9.1.1",
|
||||
"typescript": "4.1.3",
|
||||
"webpack": "5.11.1",
|
||||
"webpack-cli": "4.3.0",
|
||||
"webpack-cli": "4.3.1",
|
||||
"webpack-node-externals": "2.5.2"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
@@ -22,7 +22,7 @@ export enum ServiceIdentifiers {
|
||||
ICodeTransformerNamesGroupsBuilder = 'ICodeTransformerNamesGroupsBuilder',
|
||||
ICodeTransformersRunner = 'ICodeTransformersRunner',
|
||||
ICryptUtils = 'ICryptUtils',
|
||||
ICryptUtilsSwappedAlphabet = 'ICryptUtilsSwappedAlphabet',
|
||||
ICryptUtilsStringArray = 'ICryptUtilsStringArray',
|
||||
ICustomCodeHelper = 'ICustomCodeHelper',
|
||||
ICustomCodeHelperGroup = 'ICustomCodeHelperGroup',
|
||||
IControlFlowReplacer = 'IControlFlowReplacer',
|
||||
|
||||
@@ -3,14 +3,14 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
|
||||
|
||||
import { IArrayUtils } from '../../../interfaces/utils/IArrayUtils';
|
||||
import { ICryptUtils } from '../../../interfaces/utils/ICryptUtils';
|
||||
import { ICryptUtilsSwappedAlphabet } from '../../../interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { ICryptUtilsStringArray } from '../../../interfaces/utils/ICryptUtilsStringArray';
|
||||
import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder';
|
||||
import { ILevelledTopologicalSorter } from '../../../interfaces/utils/ILevelledTopologicalSorter';
|
||||
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
|
||||
|
||||
import { ArrayUtils } from '../../../utils/ArrayUtils';
|
||||
import { CryptUtils } from '../../../utils/CryptUtils';
|
||||
import { CryptUtilsSwappedAlphabet } from '../../../utils/CryptUtilsSwappedAlphabet';
|
||||
import { CryptUtilsStringArray } from '../../../utils/CryptUtilsStringArray';
|
||||
import { EscapeSequenceEncoder } from '../../../utils/EscapeSequenceEncoder';
|
||||
import { LevelledTopologicalSorter } from '../../../utils/LevelledTopologicalSorter';
|
||||
import { RandomGenerator } from '../../../utils/RandomGenerator';
|
||||
@@ -31,9 +31,9 @@ export const utilsModule: interfaces.ContainerModule = new ContainerModule((bind
|
||||
.to(CryptUtils)
|
||||
.inSingletonScope();
|
||||
|
||||
// crypt utils with swapped alphabet
|
||||
bind<ICryptUtilsSwappedAlphabet>(ServiceIdentifiers.ICryptUtilsSwappedAlphabet)
|
||||
.to(CryptUtilsSwappedAlphabet)
|
||||
// crypt utils for string array
|
||||
bind<ICryptUtilsStringArray>(ServiceIdentifiers.ICryptUtilsStringArray)
|
||||
.to(CryptUtilsStringArray)
|
||||
.inSingletonScope();
|
||||
|
||||
// escape sequence encoder
|
||||
|
||||
+3
-2
@@ -1,6 +1,8 @@
|
||||
import { base64alphabetSwapped } from '../../../../constants/Base64AlphabetSwapped';
|
||||
|
||||
/**
|
||||
* This atob logic completely ignores padding characters
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
export function AtobTemplate (): string {
|
||||
@@ -8,11 +10,10 @@ export function AtobTemplate (): string {
|
||||
var {atobFunctionName} = function (input) {
|
||||
const chars = '${base64alphabetSwapped}';
|
||||
|
||||
const str = String(input).replace(/=+$/, '');
|
||||
let output = '';
|
||||
for (
|
||||
let bc = 0, bs, buffer, idx = 0;
|
||||
buffer = str.charAt(idx++);
|
||||
buffer = input.charAt(idx++);
|
||||
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
|
||||
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
|
||||
) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
import { ICryptUtils } from './ICryptUtils';
|
||||
|
||||
export interface ICryptUtilsSwappedAlphabet extends ICryptUtils {}
|
||||
export interface ICryptUtilsStringArray extends ICryptUtils {}
|
||||
@@ -5,7 +5,7 @@ import { TIdentifierNamesGeneratorFactory } from '../../types/container/generato
|
||||
import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
|
||||
|
||||
import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
|
||||
import { ICryptUtilsSwappedAlphabet } from '../../interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { ICryptUtilsStringArray } from '../../interfaces/utils/ICryptUtilsStringArray';
|
||||
import { IEncodedValue } from '../../interfaces/IEncodedValue';
|
||||
import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
@@ -60,9 +60,9 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
private readonly arrayUtils: IArrayUtils;
|
||||
|
||||
/**
|
||||
* @type {ICryptUtilsSwappedAlphabet}
|
||||
* @type {ICryptUtilsStringArray}
|
||||
*/
|
||||
private readonly cryptUtilsSwappedAlphabet: ICryptUtilsSwappedAlphabet;
|
||||
private readonly cryptUtilsStringArray: ICryptUtilsStringArray;
|
||||
|
||||
/**
|
||||
* @type {IIdentifierNamesGenerator}
|
||||
@@ -104,7 +104,7 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
* @param {IArrayUtils} arrayUtils
|
||||
* @param {IRandomGenerator} randomGenerator
|
||||
* @param {IOptions} options
|
||||
* @param {ICryptUtilsSwappedAlphabet} cryptUtilsSwappedAlphabet
|
||||
* @param {ICryptUtilsStringArray} cryptUtilsStringArray
|
||||
*/
|
||||
public constructor (
|
||||
@inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
|
||||
@@ -112,13 +112,13 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
@inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,
|
||||
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
|
||||
@inject(ServiceIdentifiers.IOptions) options: IOptions,
|
||||
@inject(ServiceIdentifiers.ICryptUtilsSwappedAlphabet) cryptUtilsSwappedAlphabet: ICryptUtilsSwappedAlphabet
|
||||
@inject(ServiceIdentifiers.ICryptUtilsStringArray) cryptUtilsStringArray: ICryptUtilsStringArray
|
||||
) {
|
||||
super(randomGenerator, options);
|
||||
|
||||
this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
|
||||
this.arrayUtils = arrayUtils;
|
||||
this.cryptUtilsSwappedAlphabet = cryptUtilsSwappedAlphabet;
|
||||
this.cryptUtilsStringArray = cryptUtilsStringArray;
|
||||
|
||||
this.rc4Keys = this.randomGenerator.getRandomGenerator()
|
||||
.n(
|
||||
@@ -303,7 +303,7 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
*/
|
||||
case StringArrayEncoding.Rc4: {
|
||||
const decodeKey: string = this.randomGenerator.getRandomGenerator().pickone(this.rc4Keys);
|
||||
const encodedValue: string = this.cryptUtilsSwappedAlphabet.btoa(this.cryptUtilsSwappedAlphabet.rc4(value, decodeKey));
|
||||
const encodedValue: string = this.cryptUtilsStringArray.btoa(this.cryptUtilsStringArray.rc4(value, decodeKey));
|
||||
|
||||
const encodedValueSources: string[] = this.rc4EncodedValuesSourcesCache.get(encodedValue) ?? [];
|
||||
let encodedValueSourcesLength: number = encodedValueSources.length;
|
||||
@@ -326,7 +326,7 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
|
||||
case StringArrayEncoding.Base64: {
|
||||
const decodeKey: null = null;
|
||||
const encodedValue: string = this.cryptUtilsSwappedAlphabet.btoa(value);
|
||||
const encodedValue: string = this.cryptUtilsStringArray.btoa(value);
|
||||
|
||||
return { encodedValue, encoding, decodeKey };
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
|
||||
|
||||
import { ICryptUtilsSwappedAlphabet } from '../interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { ICryptUtilsStringArray } from '../interfaces/utils/ICryptUtilsStringArray';
|
||||
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
|
||||
|
||||
import { base64alphabetSwapped } from '../constants/Base64AlphabetSwapped';
|
||||
@@ -9,7 +9,7 @@ import { base64alphabetSwapped } from '../constants/Base64AlphabetSwapped';
|
||||
import { CryptUtils } from './CryptUtils';
|
||||
|
||||
@injectable()
|
||||
export class CryptUtilsSwappedAlphabet extends CryptUtils implements ICryptUtilsSwappedAlphabet {
|
||||
export class CryptUtilsStringArray extends CryptUtils implements ICryptUtilsStringArray {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -23,4 +23,16 @@ export class CryptUtilsSwappedAlphabet extends CryptUtils implements ICryptUtils
|
||||
) {
|
||||
super(randomGenerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes base64 encoded string without padding characters and with swapped alphabet
|
||||
*
|
||||
* @param {string} string
|
||||
* @returns {string}
|
||||
*/
|
||||
public btoa (string: string): string {
|
||||
const output = super.btoa(string);
|
||||
|
||||
return output.replace(/=+$/, '');
|
||||
}
|
||||
}
|
||||
+12
-10
@@ -1,29 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
|
||||
import { StringArrayEncoding } from '../../src/enums/node-transformers/string-array-transformers/StringArrayEncoding';
|
||||
|
||||
(function () {
|
||||
const JavaScriptObfuscator: any = require('../../index');
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
console.log('222');
|
||||
console.log('1');
|
||||
console.log('22');
|
||||
console.log('333');
|
||||
console.log('444');
|
||||
console.log('555');
|
||||
console.log('999');
|
||||
console.log('888');
|
||||
console.log('777');
|
||||
console.log('666');
|
||||
console.log('111');
|
||||
console.log('4444');
|
||||
console.log('55555');
|
||||
console.log('666666');
|
||||
console.log('7777777');
|
||||
console.log('88888888');
|
||||
console.log('999999999');
|
||||
`,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
compact: false,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
shuffleStringArray: true,
|
||||
rotateStringArray: true
|
||||
stringArrayEncoding: [
|
||||
StringArrayEncoding.Rc4
|
||||
]
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
|
||||
+48
-3
@@ -6,7 +6,7 @@ import { assert } from 'chai';
|
||||
|
||||
import { ServiceIdentifiers } from '../../../../../../src/container/ServiceIdentifiers';
|
||||
|
||||
import { ICryptUtilsSwappedAlphabet } from '../../../../../../src/interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { ICryptUtilsStringArray } from '../../../../../../src/interfaces/utils/ICryptUtilsStringArray';
|
||||
import { IInversifyContainerFacade } from '../../../../../../src/interfaces/container/IInversifyContainerFacade';
|
||||
import { IObfuscatedCode } from '../../../../../../src/interfaces/source-code/IObfuscatedCode';
|
||||
import { IRandomGenerator } from '../../../../../../src/interfaces/utils/IRandomGenerator';
|
||||
@@ -22,13 +22,14 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/preset
|
||||
import { InversifyContainerFacade } from '../../../../../../src/container/InversifyContainerFacade';
|
||||
import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
|
||||
import { readFileAsString } from '../../../../../helpers/readFileAsString';
|
||||
import { swapLettersCase } from '../../../../../helpers/swapLettersCase';
|
||||
|
||||
describe('StringArrayCallsWrapperTemplate', () => {
|
||||
const stringArrayName: string = 'stringArrayName';
|
||||
const stringArrayCallsWrapperName: string = 'stringArrayCallsWrapperName';
|
||||
const atobFunctionName: string = 'atob';
|
||||
|
||||
let cryptUtilsSwappedAlphabet: ICryptUtilsSwappedAlphabet,
|
||||
let cryptUtilsSwappedAlphabet: ICryptUtilsStringArray,
|
||||
randomGenerator: IRandomGenerator;
|
||||
|
||||
before(() => {
|
||||
@@ -36,7 +37,7 @@ describe('StringArrayCallsWrapperTemplate', () => {
|
||||
|
||||
inversifyContainerFacade.load('', '', {});
|
||||
cryptUtilsSwappedAlphabet = inversifyContainerFacade
|
||||
.get<ICryptUtilsSwappedAlphabet>(ServiceIdentifiers.ICryptUtilsSwappedAlphabet);
|
||||
.get<ICryptUtilsStringArray>(ServiceIdentifiers.ICryptUtilsStringArray);
|
||||
randomGenerator = inversifyContainerFacade
|
||||
.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator);
|
||||
});
|
||||
@@ -127,6 +128,50 @@ describe('StringArrayCallsWrapperTemplate', () => {
|
||||
assert.deepEqual(decodedValue, expectedDecodedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: no regexp inside atob template', () => {
|
||||
const indexShiftAmount: number = 0;
|
||||
|
||||
const expectedRegExpTestValue: string = '12345';
|
||||
|
||||
let decodedValue: string;
|
||||
|
||||
before(() => {
|
||||
const atobPolyfill = format(AtobTemplate(), {
|
||||
atobFunctionName
|
||||
});
|
||||
const atobDecodeTemplate: string = format(
|
||||
StringArrayBase64DecodeTemplate(randomGenerator),
|
||||
{
|
||||
atobPolyfill,
|
||||
atobFunctionName,
|
||||
selfDefendingCode: '',
|
||||
stringArrayCallsWrapperName
|
||||
}
|
||||
);
|
||||
const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), {
|
||||
decodeCodeHelperTemplate: atobDecodeTemplate,
|
||||
indexShiftAmount,
|
||||
stringArrayCallsWrapperName,
|
||||
stringArrayName
|
||||
});
|
||||
|
||||
decodedValue = Function(`
|
||||
var ${stringArrayName} = ['${swapLettersCase('c3RyaQ==')}'];
|
||||
|
||||
${stringArrayCallsWrapperTemplate}
|
||||
|
||||
/(.+)/.test("12345");
|
||||
${stringArrayCallsWrapperName}(0x0);
|
||||
|
||||
return RegExp.$1;
|
||||
`)();
|
||||
});
|
||||
|
||||
it('should correctly return RegExp.$1 match without mutation by atob template', () => {
|
||||
assert.deepEqual(decodedValue, expectedRegExpTestValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: `rc4` encoding', () => {
|
||||
|
||||
+2
-2
@@ -406,7 +406,7 @@ describe('StringArrayTransformer', function () {
|
||||
});
|
||||
|
||||
describe('Variant #7: base64 encoding', () => {
|
||||
const stringArrayRegExp: RegExp = new RegExp(`^var _0x([a-f0-9]){4} *= *\\['${swapLettersCase('dGVzdA==')}'];`);
|
||||
const stringArrayRegExp: RegExp = new RegExp(`^var _0x([a-f0-9]){4} *= *\\['${swapLettersCase('dGVzdA')}'];`);
|
||||
const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\(0x0\);/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
@@ -507,7 +507,7 @@ describe('StringArrayTransformer', function () {
|
||||
const expectedMatchesDelta: number = 0.15;
|
||||
|
||||
const noneEncodingRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['test'\];/;
|
||||
const base64EncodingRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['DgvZDa=='\];/;
|
||||
const base64EncodingRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['DgvZDa'\];/;
|
||||
|
||||
let noneEncodingMatchesCount: number = 0;
|
||||
let base64EncodingMatchesCount: number = 0;
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ import './unit-tests/storages/string-array-transformers/string-array/StringArray
|
||||
import './unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec';
|
||||
import './unit-tests/utils/ArrayUtils.spec';
|
||||
import './unit-tests/utils/CryptUtils.spec';
|
||||
import './unit-tests/utils/CryptUtilsSwappedAlphabet.spec';
|
||||
import './unit-tests/utils/CryptUtilsStringArray.spec';
|
||||
import './unit-tests/utils/EscapeSequenceEncoder.spec';
|
||||
import './unit-tests/utils/LevelledTopologicalSorter.spec';
|
||||
import './unit-tests/utils/NumberUtils.spec';
|
||||
|
||||
@@ -9,8 +9,6 @@ import { IInversifyContainerFacade } from '../../../src/interfaces/container/IIn
|
||||
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
|
||||
import { swapLettersCase } from '../../helpers/swapLettersCase';
|
||||
|
||||
describe('CryptUtils', () => {
|
||||
let cryptUtils: ICryptUtils;
|
||||
|
||||
@@ -22,16 +20,32 @@ describe('CryptUtils', () => {
|
||||
});
|
||||
|
||||
describe('btoa', () => {
|
||||
const expectedString: string = swapLettersCase('C3rYAw5N');
|
||||
describe('Variant #1: basic', () => {
|
||||
const expectedString: string = 'c3RyaW5n';
|
||||
|
||||
let string: string;
|
||||
let string: string;
|
||||
|
||||
before(() => {
|
||||
string = cryptUtils.btoa('string');
|
||||
});
|
||||
before(() => {
|
||||
string = cryptUtils.btoa('string');
|
||||
});
|
||||
|
||||
it('should create a base-64 encoded string from a given string', () => {
|
||||
assert.equal(string, expectedString);
|
||||
it('should create a base-64 encoded string from a given string', () => {
|
||||
assert.equal(string, expectedString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: padding characters', () => {
|
||||
const expectedString: string = 'c3RyaQ==';
|
||||
|
||||
let string: string;
|
||||
|
||||
before(() => {
|
||||
string = cryptUtils.btoa('stri');
|
||||
});
|
||||
|
||||
it('should create a base-64 encoded string from a given string with padding characters', () => {
|
||||
assert.equal(string, expectedString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'reflect-metadata';
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
|
||||
|
||||
import { ICryptUtilsStringArray } from '../../../src/interfaces/utils/ICryptUtilsStringArray';
|
||||
import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
|
||||
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
|
||||
import { swapLettersCase } from '../../helpers/swapLettersCase';
|
||||
|
||||
describe('CryptUtilsStringArray', () => {
|
||||
let cryptUtilsStringArray: ICryptUtilsStringArray;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load('', '', {});
|
||||
cryptUtilsStringArray = inversifyContainerFacade
|
||||
.get<ICryptUtilsStringArray>(ServiceIdentifiers.ICryptUtilsStringArray);
|
||||
});
|
||||
|
||||
describe('btoa', () => {
|
||||
describe('Variant #1: basic', () => {
|
||||
const expectedString: string = swapLettersCase('c3RyaW5n');
|
||||
|
||||
let string: string;
|
||||
|
||||
before(() => {
|
||||
string = cryptUtilsStringArray.btoa('string');
|
||||
});
|
||||
|
||||
it('should create a base-64 encoded string with swapped alphabet from a given string', () => {
|
||||
assert.equal(string, expectedString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: no padding characters', () => {
|
||||
const expectedString: string = swapLettersCase('c3RyaQ');
|
||||
|
||||
let string: string;
|
||||
|
||||
before(() => {
|
||||
string = cryptUtilsStringArray.btoa('stri');
|
||||
});
|
||||
|
||||
it('should create a base-64 encoded string from a given string without padding characters', () => {
|
||||
assert.equal(string, expectedString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('rc4', () => {
|
||||
const string: string = 'test';
|
||||
const key: string = 'key';
|
||||
|
||||
let encodedString: string,
|
||||
decodedString: string;
|
||||
|
||||
before(() => {
|
||||
encodedString = cryptUtilsStringArray.rc4(string, key);
|
||||
decodedString = cryptUtilsStringArray.rc4(encodedString, key);
|
||||
});
|
||||
|
||||
it('should encode string using the rc4 algorithm', () => {
|
||||
assert.notEqual(encodedString, string);
|
||||
});
|
||||
|
||||
it('should encode and successfully decode string using the rc4 algorithm', () => {
|
||||
assert.equal(decodedString, string);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,59 +0,0 @@
|
||||
import 'reflect-metadata';
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
|
||||
|
||||
import { ICryptUtilsSwappedAlphabet } from '../../../src/interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
|
||||
|
||||
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
|
||||
|
||||
import { swapLettersCase } from '../../helpers/swapLettersCase';
|
||||
|
||||
describe('CryptUtilsSwappedAlphabet', () => {
|
||||
let cryptUtilsSwappedAlphabet: ICryptUtilsSwappedAlphabet;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load('', '', {});
|
||||
cryptUtilsSwappedAlphabet = inversifyContainerFacade
|
||||
.get<ICryptUtilsSwappedAlphabet>(ServiceIdentifiers.ICryptUtilsSwappedAlphabet);
|
||||
});
|
||||
|
||||
describe('btoa', () => {
|
||||
const expectedString: string = swapLettersCase('c3RyaW5n');
|
||||
|
||||
let string: string;
|
||||
|
||||
before(() => {
|
||||
string = cryptUtilsSwappedAlphabet.btoa('string');
|
||||
});
|
||||
|
||||
it('should create a base-64 encoded string with swapped alphabet from a given string', () => {
|
||||
assert.equal(string, expectedString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rc4', () => {
|
||||
const string: string = 'test';
|
||||
const key: string = 'key';
|
||||
|
||||
let encodedString: string,
|
||||
decodedString: string;
|
||||
|
||||
before(() => {
|
||||
encodedString = cryptUtilsSwappedAlphabet.rc4(string, key);
|
||||
decodedString = cryptUtilsSwappedAlphabet.rc4(encodedString, key);
|
||||
});
|
||||
|
||||
it('should encode string using the rc4 algorithm', () => {
|
||||
assert.notEqual(encodedString, string);
|
||||
});
|
||||
|
||||
it('should encode and successfully decode string using the rc4 algorithm', () => {
|
||||
assert.equal(decodedString, string);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -805,17 +805,17 @@
|
||||
"@webassemblyjs/wast-parser" "1.9.1"
|
||||
"@xtuc/long" "4.2.2"
|
||||
|
||||
"@webpack-cli/info@^1.2.0":
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-1.2.0.tgz#6051d6adf3618df664f4945a2b76355c00f83f0d"
|
||||
integrity sha512-+wA8lBKopgKmN76BSGJVJby5ZXDlsrO6p/nm7fUBsHznRNWB/ozotJP7Yfcz8JPfqeG2LxwYlTH2u6D9a/0XAw==
|
||||
"@webpack-cli/info@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-1.2.1.tgz#af98311f983d0b9fce7284cfcf1acaf1e9f4879c"
|
||||
integrity sha512-fLnDML5HZ5AEKzHul8xLAksoKN2cibu6MgonkUj8R9V7bbeVRkd1XbGEGWrAUNYHbX1jcqCsDEpBviE5StPMzQ==
|
||||
dependencies:
|
||||
envinfo "^7.7.3"
|
||||
|
||||
"@webpack-cli/serve@^1.2.0":
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.2.0.tgz#8cb2c1e95426f5caed1f3bf9d7ccf3ea41d85f52"
|
||||
integrity sha512-jI3P7jMp/AXDSPkM+ClwRcJZbxnlvNC8bVZBmyRr4scMMZ4p5WQcXkw3Q+Hc7RQekomJlBMN+UQGliT4hhG8Vw==
|
||||
"@webpack-cli/serve@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.2.1.tgz#7513d7a769e3f97958de799b5b49874425ae3396"
|
||||
integrity sha512-Zj1z6AyS+vqV6Hfi7ngCjFGdHV5EwZNIHo6QfFTNe9PyW+zBU1zJ9BiOW1pmUEq950RC4+Dym6flyA/61/vhyw==
|
||||
|
||||
"@xtuc/ieee754@^1.2.0":
|
||||
version "1.2.0"
|
||||
@@ -1401,7 +1401,7 @@ cross-spawn@^7.0.0:
|
||||
shebang-command "^2.0.0"
|
||||
which "^2.0.1"
|
||||
|
||||
cross-spawn@^7.0.1:
|
||||
cross-spawn@^7.0.1, cross-spawn@^7.0.3:
|
||||
version "7.0.3"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
|
||||
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
|
||||
@@ -1540,13 +1540,6 @@ emojis-list@^3.0.0:
|
||||
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78"
|
||||
integrity sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==
|
||||
|
||||
end-of-stream@^1.1.0:
|
||||
version "1.4.4"
|
||||
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
|
||||
integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==
|
||||
dependencies:
|
||||
once "^1.4.0"
|
||||
|
||||
enhanced-resolve@^4.0.0:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.1.tgz#2937e2b8066cd0fe7ce0990a98f0d71a35189f66"
|
||||
@@ -1950,19 +1943,19 @@ events@^3.2.0:
|
||||
resolved "https://registry.yarnpkg.com/events/-/events-3.2.0.tgz#93b87c18f8efcd4202a461aec4dfc0556b639379"
|
||||
integrity sha512-/46HWwbfCX2xTawVfkKLGxMifJYQBWMwY1mjywRtb4c9x8l5NP3KoJtnIOiL1hfdRkIuYhETxQlo62IF8tcnlg==
|
||||
|
||||
execa@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"
|
||||
integrity sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==
|
||||
execa@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/execa/-/execa-5.0.0.tgz#4029b0007998a841fbd1032e5f4de86a3c1e3376"
|
||||
integrity sha512-ov6w/2LCiuyO4RLYGdpFGjkcs0wMTgGE8PrkTHikeUy5iJekXyPIKUjifk5CsE0pt7sMCrMZ3YNqoCj6idQOnQ==
|
||||
dependencies:
|
||||
cross-spawn "^7.0.0"
|
||||
get-stream "^5.0.0"
|
||||
human-signals "^1.1.1"
|
||||
cross-spawn "^7.0.3"
|
||||
get-stream "^6.0.0"
|
||||
human-signals "^2.1.0"
|
||||
is-stream "^2.0.0"
|
||||
merge-stream "^2.0.0"
|
||||
npm-run-path "^4.0.0"
|
||||
onetime "^5.1.0"
|
||||
signal-exit "^3.0.2"
|
||||
npm-run-path "^4.0.1"
|
||||
onetime "^5.1.2"
|
||||
signal-exit "^3.0.3"
|
||||
strip-final-newline "^2.0.0"
|
||||
|
||||
fast-deep-equal@3.1.3:
|
||||
@@ -2183,12 +2176,10 @@ get-package-type@^0.1.0:
|
||||
resolved "https://registry.yarnpkg.com/get-package-type/-/get-package-type-0.1.0.tgz#8de2d803cff44df3bc6c456e6668b36c3926e11a"
|
||||
integrity sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==
|
||||
|
||||
get-stream@^5.0.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.2.0.tgz#4966a1795ee5ace65e706c4b7beb71257d6e22d3"
|
||||
integrity sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==
|
||||
dependencies:
|
||||
pump "^3.0.0"
|
||||
get-stream@^6.0.0:
|
||||
version "6.0.0"
|
||||
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.0.tgz#3e0012cb6827319da2706e601a1583e8629a6718"
|
||||
integrity sha512-A1B3Bh1UmL0bidM/YX2NsCOTnGJePL9rO/M+Mw3m9f2gUpfokS0hi5Eah0WSUEWZdZhIZtMjkIYS7mDfOqNHbg==
|
||||
|
||||
glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0:
|
||||
version "5.1.1"
|
||||
@@ -2308,10 +2299,10 @@ html-escaper@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.1.tgz#beed86b5d2b921e92533aa11bce6d8e3b583dee7"
|
||||
integrity sha512-hNX23TjWwD3q56HpWjUHOKj1+4KKlnjv9PcmBUYKVpga+2cnb9nDx/B1o0yO4n+RZXZdiNxzx6B24C9aNMTkkQ==
|
||||
|
||||
human-signals@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
|
||||
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==
|
||||
human-signals@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
|
||||
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
|
||||
|
||||
ignore@^4.0.6:
|
||||
version "4.0.6"
|
||||
@@ -3040,7 +3031,7 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
|
||||
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
|
||||
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
|
||||
|
||||
npm-run-path@^4.0.0:
|
||||
npm-run-path@^4.0.1:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
|
||||
integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==
|
||||
@@ -3138,14 +3129,14 @@ observable-fns@^0.5.1:
|
||||
resolved "https://registry.yarnpkg.com/observable-fns/-/observable-fns-0.5.1.tgz#9b56478690dd0fa8603e3a7e7d2975d88bca0904"
|
||||
integrity sha512-wf7g4Jpo1Wt2KIqZKLGeiuLOEMqpaOZ5gJn7DmSdqXgTdxRwSdBhWegQQpPteQ2gZvzCKqNNpwb853wcpA0j7A==
|
||||
|
||||
once@^1.3.0, once@^1.3.1, once@^1.4.0:
|
||||
once@^1.3.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
|
||||
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
|
||||
dependencies:
|
||||
wrappy "1"
|
||||
|
||||
onetime@^5.1.0:
|
||||
onetime@^5.1.2:
|
||||
version "5.1.2"
|
||||
resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e"
|
||||
integrity sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==
|
||||
@@ -3422,14 +3413,6 @@ pseudomap@^1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
|
||||
integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM=
|
||||
|
||||
pump@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"
|
||||
integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==
|
||||
dependencies:
|
||||
end-of-stream "^1.1.0"
|
||||
once "^1.3.1"
|
||||
|
||||
punycode@^2.1.0:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
|
||||
@@ -3703,6 +3686,11 @@ signal-exit@^3.0.2:
|
||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
|
||||
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
|
||||
|
||||
signal-exit@^3.0.3:
|
||||
version "3.0.3"
|
||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
|
||||
integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==
|
||||
|
||||
sinon@9.2.2:
|
||||
version "9.2.2"
|
||||
resolved "https://registry.yarnpkg.com/sinon/-/sinon-9.2.2.tgz#b83cf5d43838f99cfa3644453f4c7db23e7bd535"
|
||||
@@ -4218,18 +4206,18 @@ watchpack@^2.0.0:
|
||||
glob-to-regexp "^0.4.1"
|
||||
graceful-fs "^4.1.2"
|
||||
|
||||
webpack-cli@4.3.0:
|
||||
version "4.3.0"
|
||||
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.3.0.tgz#e39303bf9f8002de122903e97029f3443d0f9174"
|
||||
integrity sha512-gve+BBKrzMPTOYDjupzV8JchUznhVWMKtWM1hFIQWi6XoeLvGNoQwkrtMWVb+aJ437GgCKdta7sIn10v621pKA==
|
||||
webpack-cli@4.3.1:
|
||||
version "4.3.1"
|
||||
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.3.1.tgz#87a7873bc9c6a4708aa657759274b691e72a04a8"
|
||||
integrity sha512-/F4+9QNZM/qKzzL9/06Am8NXIkGV+/NqQ62Dx7DSqudxxpAgBqYn6V7+zp+0Y7JuWksKUbczRY3wMTd+7Uj6OA==
|
||||
dependencies:
|
||||
"@discoveryjs/json-ext" "^0.5.0"
|
||||
"@webpack-cli/info" "^1.2.0"
|
||||
"@webpack-cli/serve" "^1.2.0"
|
||||
"@webpack-cli/info" "^1.2.1"
|
||||
"@webpack-cli/serve" "^1.2.1"
|
||||
colorette "^1.2.1"
|
||||
commander "^6.2.0"
|
||||
enquirer "^2.3.6"
|
||||
execa "^4.1.0"
|
||||
execa "^5.0.0"
|
||||
fastest-levenshtein "^1.0.12"
|
||||
import-local "^3.0.2"
|
||||
interpret "^2.2.0"
|
||||
|
||||
Reference in New Issue
Block a user