2017-12-04 7 views
0

Google Apps ScriptでURLリクエストを行う必要があります。そのために、sha 1アルゴリズムとbase64エンコードを使用してログインとパスワードのエンコードを行う必要があります。リクエストのdocumantationでは、私は以下のPHPコードを持っている:Google Apps Script - sha1とbase64を使用したURLリクエストのエンコード

$string = "loginpassword2017-15-04T09:25:00"; $hash = sha1($string, true); $hash = base64_encode($hash);

だから、Google Appsのスクリプトでは、私は次のコードを使用し

function GetSHA1(input) { var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, input); var txtHash = ''; for (j = 0; j <rawHash.length; j++) { var hashVal = rawHash[j]; if (hashVal < 0) hashVal += 256; if (hashVal.toString(16).length == 1) txtHash += "0"; txtHash += hashVal.toString(16); } return txtHash; }

、その後、機能

Utilities.base64Encode

最後に私はURLリクエストを行いますが、カチオンは成功しない。誰かがGoogle Apps Scriptでph1 sha1とbase64encodeを行う方法を知っていますか?おかげ

+0

「認証は失敗しました」という意味はどうですか? – Kos

+0

これはウェブサービスに接続するためのURLリクエストです 私は実際に問題を発見しました。私はgoogle appsスクリプトでテストしたさまざまなsha1がphpのものとは異なります(私はphpで暗号化をテストし、google appsスクリプトでテストしました。 ) – BrtD

+0

今私の問題は、PHPの1つと同じGoogleのアプリケーションのスクリプトを見つけることです – BrtD

答えて

0

あなたはByte[]配列がUtilities::base64EncodeWebSafe呼び出しに直接Utilities::computeDigestから返さ渡すことができます。あなたは次のようなことをすることができます:

function getLoginHash(loginData) { 

    return Utilities.base64EncodeWebSafe(Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, loginData)); 

} 
関連する問題