How to decrypt data from the result of an IE 11 encrypt operation using AES-GCM

https://stackoverflow.com/questions/41449185/how-to-decrypt-data-from-the-result-of-an-ie-11-encrypt-operation-using-aes-gcm

重要的是第一个回复!

<!DOCTYPE html>
<html>
<body>
<script>
	let plainText = new Uint8Array([1]);
	let key;
	
	let secretDic = {
        a: [88, 88, 88, 88, 88, 88, 88, 88,
        88, 88, 88, 88, 88, 88, 88, 88,
        88, 88, 88, 88, 88, 88, 88, 88,
        88, 88, 88, 88, 88, 88, 88, 88]
    };
	
	let keyBuf = new Uint8Array(secretDic.a);
	let iv = window.msCrypto.getRandomValues(new Uint8Array(12));
	let encResult;
	let importOp = window.msCrypto.subtle.importKey('raw', 
		keyBuf,
		{ name: 'AES-GCM' }, 
		true, // false
		['encrypt', 'decrypt']);
		
	importOp.oncomplete = function(e) {
		key = e.target.result;
		console.log('key: ');
		console.log(key);
		
		let encryptOp = window.msCrypto.subtle.encrypt({
			name: 'AES-GCM',
			iv: iv,
			tagLength: 128
		}, key, plainText);
		encryptOp.oncomplete = function (e) {
			encResult = e.target.result;
			console.log('encResult');
			console.log(encResult);
			
			let decryptOp = window.msCrypto.subtle.decrypt({
				name: 'AES-GCM',
				iv: iv,
				tag: new Uint8Array(encResult.tag)
			}, key, new Uint8Array(encResult.ciphertext));
			decryptOp.onerror = function(er){
				console.log('err:');
				console.log(er);
			};
			
			console.log('decrypt');
			console.log(decryptOp);
		};
	};
	
</script>
</body>
</html>

发表评论