1 function stringToUint8Array(str)
3 var result = new Uint8Array(str.length);
4 for(var i = 0; i < str.length; i++) {
5 result[i] = str.charCodeAt(i);
10 // For Clear Key, MediaKeySession.update() takes a JSON Web Key (JWK) Set,
11 // which contains a set of cryptographic keys represented by JSON. These helper
12 // functions help wrap raw keys into a JWK set.
14 // https://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#simple-decryption-clear-key
15 // http://tools.ietf.org/html/draft-ietf-jose-json-web-key
17 // Encodes data into base64 string without trailing '='.
18 function base64Encode(data)
20 var result = btoa(String.fromCharCode.apply(null, data));
21 return result.replace(/=+$/g, '');
24 // Creates a JWK from raw key ID and key.
25 function createJWK(keyId, key)
27 var jwk = "{\"kty\":\"oct\",\"kid\":\"";
28 jwk += base64Encode(keyId);
30 jwk += base64Encode(key);
35 // Creates a JWK Set from multiple JWKs.
36 function createJWKSet()
38 var jwkSet = "{\"keys\":[";
39 for (var i = 0; i < arguments.length; i++) {
42 jwkSet += arguments[i];