3

Chrome (최초 웹 암호화 지원 이후), Firefox (최초 웹 암호화 지원 이후) 및 Safari TP (10.2)에서 웹 암호화 API (https://www.w3.org/TR/WebCryptoAPI/))에 WebCrypto API (https://github.com/PeculiarVentures/webcrypto-liner) 용 폴리 필을 지원하는 WebCrypto Liner를 지원합니다.Microsoft Edge (38.14393.0.0)를 사용하는 웹 암호화 API

이제 Microsoft Edge를 사용하여 코드를 테스트하고 싶습니다. 그러나 샘플 ArrayBuffer를 암호화하고 해독하는 것은 이미 실패합니다. 여기 코드는 : 자사의 크롬, 파이어 폭스, 심지어 사파리에서 잘 작업하는 동안

var crypto = window.crypto; 
if (crypto.subtle) { 
    var aesGcmKey = null; 
    // always create a new, random iv in production systems!!! 
    var tempIv = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); 
    // needed for edge, if additional data missing decrypting is failing 
    var tempAdditionalData = new Uint8Array(0); 
    var dataToEncrypt = new Uint8Array([1, 2, 3, 4, 5]); 

    // 1.) generate key 
    var generateKeyPromise = crypto.subtle.generateKey(
     {name: "AES-GCM", length: 256}, true, ["encrypt", "decrypt"] 
    ); 
    generateKeyPromise.then(function (tempKey) { 
     aesGcmKey = tempKey; 
     // 2.) start encryption with this key 
     var encryptedDataPromise = crypto.subtle.encrypt(
      {name: "AES-GCM", iv: tempIv, additionalData: tempAdditionalData, tagLength: 128}, 
      aesGcmKey, 
      dataToEncrypt 
     ); 
     encryptedDataPromise.then(function (encryptedData) { 
      // 3.) decrypt using same key 
      var decryptedDataPromise = crypto.subtle.decrypt(
       {name: "AES-GCM", iv: tempIv, additionalData: tempAdditionalData, tagLength: 128}, 
       aesGcmKey, 
       encryptedData 
      ); 
      decryptedDataPromise.then(function (decryptedData) { 
       // 4.) compare decrypted array buffer and inital data 
       console.log('data decrypted!'); 
       console.log(decryptedData); 
      }); 
      decryptedDataPromise.catch(function (error) { 
       console.log('decrypting sample data failed'); 
       console.log(error); 
      }); 
     }); 
     // if 2.) is failing 
     encryptedDataPromise.catch(function (error) { 
      console.log('encrypting sample data failed'); 
      console.log(error); 
     }); 
    }); 
    // if 1.) is failing 
    generateKeyPromise.catch(function (error) { 
     console.log('creating aec gcm key failed'); 
     console.log(error); 
    }); 
} 

이 코드는, 가장자리에 암호 해독 단계 (코드에서 3 단계)에 실패합니다. decryptedDataPromise 예외로 거부하지만 반환 된 데이터가 전혀 예외처럼 나던 유선 부분이 :이 Microsoft 가장자리에 실패하는 이유

[object Object] {additionalData: Uint8Array {...}, iv: Uint8Array {...}, name: "AES-GCM", tagLength: 128} 

아무도 단서가 있습니까?

+3

이 라이브 예제는 https://diafygi.github.io/webcrypto-examples/에서 AES-GCM이 Edge에서 작동 함을 보여줍니다. 따라서 매개 변수의 약간의 차이로 인해 발생합니다. 16 대신 크기 12의 IV를 시도해 볼 수 있습니까? – pedrofb

+1

위의 덧글 추가로, 당신은 'var tempAdditionalData = new Uint8Array (1);'메모가 필요해 보인다 : 1이 아닌 0 –

답변

2

하는 1 대신 0를 포함하는 크기 12 대신 16의 추가 데이터에 IV를 변경, 의견 제안 바와 같이

var tempIv = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]); 
var tempAdditionalData = new Uint8Array(1); 

추가 데이터에 대한 의견이 "// 가장자리에 필요한 가장자리의 문제를 해결 , 추가 데이터 누락 된 해독에 실패한 경우 "은 실제로 필요하지 않습니다. additionalData은 무효화 될 수 있습니다.

MSDN에서 encrypt 작업에 대해 찾고 있었지만이 동작에 대해 설명되어 있지 않습니다. 그래서 WebCrypto의 구현은 아직 성숙하지 않았고 여전히 작은 버그가 있다고 생각합니다.