mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-25 23:24:09 +03:00
1 parent
bf7f986bfd
commit
9750ac5cea
5 files changed
+93
-12
No files matched your search
@@ -53,6 +53,7 @@
|
|||||||
"@kenjiuno/decompressrtf": "^0.1.4",
|
"@kenjiuno/decompressrtf": "^0.1.4",
|
||||||
"@kenjiuno/msgreader": "^1.22.0",
|
"@kenjiuno/msgreader": "^1.22.0",
|
||||||
"@mdit/plugin-align": "^0.16.0",
|
"@mdit/plugin-align": "^0.16.0",
|
||||||
|
"@noble/ciphers": "^1.2.1",
|
||||||
"@regexper/render": "^1.0.0",
|
"@regexper/render": "^1.0.0",
|
||||||
"@sindresorhus/slugify": "^2.2.1",
|
"@sindresorhus/slugify": "^2.2.1",
|
||||||
"@tabler/icons-vue": "^3.20.0",
|
"@tabler/icons-vue": "^3.20.0",
|
||||||
|
|||||||
Generated
+8
@@ -56,6 +56,9 @@ dependencies:
|
|||||||
'@mdit/plugin-align':
|
'@mdit/plugin-align':
|
||||||
specifier: ^0.16.0
|
specifier: ^0.16.0
|
||||||
version: 0.16.0(markdown-it@14.1.0)
|
version: 0.16.0(markdown-it@14.1.0)
|
||||||
|
'@noble/ciphers':
|
||||||
|
specifier: ^1.2.1
|
||||||
|
version: 1.2.1
|
||||||
'@regexper/render':
|
'@regexper/render':
|
||||||
specifier: ^1.0.0
|
specifier: ^1.0.0
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
@@ -5098,6 +5101,11 @@ packages:
|
|||||||
dev: false
|
dev: false
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
/@noble/ciphers@1.2.1:
|
||||||
|
resolution: {integrity: sha512-rONPWMC7PeExE077uLE4oqWrZ1IvAfz3oH9LibVAcVCopJiA9R62uavnbEzdkVmJYI6M6Zgkbeb07+tWjlq2XA==}
|
||||||
|
engines: {node: ^14.21.3 || >=16}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@nodelib/fs.scandir@2.1.5:
|
/@nodelib/fs.scandir@2.1.5:
|
||||||
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
|
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
|
||||||
engines: {node: '>= 8'}
|
engines: {node: '>= 8'}
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import { Buffer } from 'node:buffer';
|
||||||
|
import { RC4, Rabbit, TripleDES, enc } from 'crypto-js';
|
||||||
|
import { managedNonce, randomBytes } from '@noble/ciphers/webcrypto';
|
||||||
|
import { aeskw, aeskwp, cbc, cfb, ctr, ecb, gcm, siv } from '@noble/ciphers/aes';
|
||||||
|
import { salsa20, xsalsa20, xsalsa20poly1305 } from '@noble/ciphers/salsa';
|
||||||
|
import { chacha12, chacha20, chacha20poly1305, chacha8, xchacha20, xchacha20poly1305 } from '@noble/ciphers/chacha';
|
||||||
|
import { bytesToUtf8, hexToBytes, utf8ToBytes } from '@noble/ciphers/utils';
|
||||||
|
|
||||||
|
function getCryptoJSKey(key: string, keyEncoding: KeyEncoding) {
|
||||||
|
return keyEncoding === 'Text' ? key : enc.Hex.parse(key);
|
||||||
|
}
|
||||||
|
function getNobleKey(key: string, keyEncoding: KeyEncoding) {
|
||||||
|
return keyEncoding === 'Text' ? utf8ToBytes(key) : hexToBytes(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCryptoJSCipher(cipher: any) {
|
||||||
|
return {
|
||||||
|
encrypt: (value: string, key: string, keyEncoding: KeyEncoding) => cipher.encrypt(value, getCryptoJSKey(key, keyEncoding), { iv: enc.Hex.parse('') }).toString(),
|
||||||
|
decrypt: (value: string, key: string, keyEncoding: KeyEncoding) => cipher.decrypt(value, getCryptoJSKey(key, keyEncoding), { iv: enc.Hex.parse('') }).toString(enc.Utf8),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function getNobleCipher(algo: any, nonceType: 'auto' | 'none' | 'manual' = 'auto', nonceSize: number = 0) {
|
||||||
|
return {
|
||||||
|
encrypt: (value: string, key: string, keyEncoding: KeyEncoding) => {
|
||||||
|
if (nonceType === 'auto') {
|
||||||
|
return Buffer.from(managedNonce(algo)(getNobleKey(key, keyEncoding)).encrypt(utf8ToBytes(value))).toString('base64');
|
||||||
|
}
|
||||||
|
else if (nonceType === 'none') {
|
||||||
|
return Buffer.from(algo(getNobleKey(key, keyEncoding)).encrypt(utf8ToBytes(value))).toString('base64');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const nonce = randomBytes(nonceSize);
|
||||||
|
return Buffer.from(new Uint8Array([...nonce, ...algo(getNobleKey(key, keyEncoding), nonce, utf8ToBytes(value))])).toString('base64');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
decrypt: (value: string, key: string, keyEncoding: KeyEncoding) => {
|
||||||
|
if (nonceType === 'auto') {
|
||||||
|
return bytesToUtf8(managedNonce(algo)(getNobleKey(key, keyEncoding)).decrypt(Buffer.from(value, 'base64')));
|
||||||
|
}
|
||||||
|
else if (nonceType === 'none') {
|
||||||
|
return bytesToUtf8(algo(getNobleKey(key, keyEncoding)).decrypt(Buffer.from(value, 'base64')));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const ciphered = Buffer.from(value, 'base64');
|
||||||
|
return bytesToUtf8(algo(getNobleKey(key, keyEncoding), ciphered.subarray(0, nonceSize), ciphered.subarray(nonceSize)));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const algos = {
|
||||||
|
'TripleDES': getCryptoJSCipher(TripleDES),
|
||||||
|
'Rabbit': getCryptoJSCipher(Rabbit),
|
||||||
|
'RC4': getCryptoJSCipher(RC4),
|
||||||
|
'AES-GCM': getNobleCipher(gcm),
|
||||||
|
'AES-SIV': getNobleCipher(siv),
|
||||||
|
'AES-CTR': getNobleCipher(ctr),
|
||||||
|
'AES-CFB': getNobleCipher(cfb),
|
||||||
|
'AES-CBC': getNobleCipher(cbc),
|
||||||
|
'AES-ECB': getNobleCipher(ecb, 'none'),
|
||||||
|
'AES-KW': getNobleCipher(aeskw, 'none'),
|
||||||
|
'AES-KWP': getNobleCipher(aeskwp, 'none'),
|
||||||
|
'Salsa-XSalsa20poly1305': getNobleCipher(xsalsa20poly1305),
|
||||||
|
'Chacha-Chacha20poly1305': getNobleCipher(chacha20poly1305),
|
||||||
|
'Chacha-XChacha20poly1305': getNobleCipher(xchacha20poly1305),
|
||||||
|
'Salsa-Salsa20': getNobleCipher(salsa20, 'manual', 8),
|
||||||
|
'Salsa-XSalsa20': getNobleCipher(xsalsa20, 'manual', 24),
|
||||||
|
'Chacha-Chacha20': getNobleCipher(chacha20, 'manual', 12),
|
||||||
|
'Chacha-XChacha20': getNobleCipher(xchacha20, 'manual', 24),
|
||||||
|
'Chacha-Chacha8': getNobleCipher(chacha8, 'manual', 12),
|
||||||
|
'Chacha-Chacha12 ': getNobleCipher(chacha12, 'manual', 12),
|
||||||
|
};
|
||||||
|
|
||||||
|
export type KeyEncoding = 'Text' | 'Hex';
|
||||||
@@ -1,24 +1,22 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { AES, RC4, Rabbit, TripleDES, enc } from 'crypto-js';
|
import type { KeyEncoding } from './encryption.service';
|
||||||
|
import { algos } from './encryption.service';
|
||||||
import { computedCatch } from '@/composable/computed/catchedComputed';
|
import { computedCatch } from '@/composable/computed/catchedComputed';
|
||||||
|
|
||||||
const algos = { AES, TripleDES, Rabbit, RC4 };
|
|
||||||
type KeyEncoding = 'Text' | 'Hex';
|
|
||||||
|
|
||||||
const cypherInput = ref('Lorem ipsum dolor sit amet');
|
const cypherInput = ref('Lorem ipsum dolor sit amet');
|
||||||
const cypherAlgo = ref<keyof typeof algos>('AES');
|
const cypherAlgo = ref<keyof typeof algos>('AES-CBC');
|
||||||
const cypherSecret = ref('my secret key');
|
const cypherSecret = ref('my secret key 16');
|
||||||
const cypherSecretEncoding = ref<KeyEncoding>('Text');
|
const cypherSecretEncoding = ref<KeyEncoding>('Text');
|
||||||
const [cypherOutput, cypherError] = computedCatch(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecretEncoding.value === 'Text' ? cypherSecret.value : enc.Hex.parse(cypherSecret.value), { iv: enc.Hex.parse('') }).toString(), {
|
const [cypherOutput, cypherError] = computedCatch(() => algos[cypherAlgo.value].encrypt(cypherInput.value, cypherSecret.value, cypherSecretEncoding.value), {
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
defaultErrorMessage: 'Unable to cypher your text',
|
defaultErrorMessage: 'Unable to cypher your text',
|
||||||
});
|
});
|
||||||
|
|
||||||
const decryptInput = ref('U2FsdGVkX1/EC3+6P5dbbkZ3e1kQ5o2yzuU0NHTjmrKnLBEwreV489Kr0DIB+uBs');
|
const decryptInput = ref('dopEIE7v5TJlhHl+0+mA4Q+BxNj4xcdTsiVGw4tmpLlkDln8lzmzavO3egJuzpCD');
|
||||||
const decryptAlgo = ref<keyof typeof algos>('AES');
|
const decryptAlgo = ref<keyof typeof algos>('AES-CBC');
|
||||||
const decryptSecret = ref('my secret key');
|
const decryptSecret = ref('my secret key 16');
|
||||||
const decryptSecretEncoding = ref<KeyEncoding>('Text');
|
const decryptSecretEncoding = ref<KeyEncoding>('Text');
|
||||||
const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecretEncoding.value === 'Text' ? decryptSecret.value : enc.Hex.parse(decryptSecret.value), { iv: enc.Hex.parse('') }).toString(enc.Utf8), {
|
const [decryptOutput, decryptError] = computedCatch(() => algos[decryptAlgo.value].decrypt(decryptInput.value, decryptSecret.value, decryptSecretEncoding.value), {
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
defaultErrorMessage: 'Unable to decrypt your text',
|
defaultErrorMessage: 'Unable to decrypt your text',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const tool = defineTool({
|
|||||||
name: translate('tools.encryption.title'),
|
name: translate('tools.encryption.title'),
|
||||||
path: '/encryption',
|
path: '/encryption',
|
||||||
description: translate('tools.encryption.description'),
|
description: translate('tools.encryption.description'),
|
||||||
keywords: ['cypher', 'encipher', 'text', 'AES', 'TripleDES', 'Rabbit', 'RC4'],
|
keywords: ['cypher', 'encipher', 'text', 'AES', 'TripleDES', 'Rabbit', 'RC4', 'Salsa', 'ChaCha'],
|
||||||
component: () => import('./encryption.vue'),
|
component: () => import('./encryption.vue'),
|
||||||
icon: Lock,
|
icon: Lock,
|
||||||
redirectFrom: ['/cypher'],
|
redirectFrom: ['/cypher'],
|
||||||
|
|||||||
Reference in new issue
Block a user