1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GASで暗号化・復号化 -cCryptoJSを使って-

Last updated at Posted at 2023-04-09

GASで暗号化、復号化を行う

ライブラリの導入

GAS のエディタの左側にある「ライブラリ」の横の「+」をクリックし、スクリプトID に 1IEkpeS8hsMSVLRdCMprij996zG6ek9UvGwcCJao_hlDMlgbWWvJpONrs を入力して検索する。cCryptoGS を追加する。

cf. CryptoJS libraries for Google Apps Script

プログラムの例

// GAS で暗号を扱う。
// 1. ライブラリの使い方
//     左の「ライブラリ」で+を押す。
//     スクリプトIDに、与えられた 1IEkpeS8hsMSVLRdCMprij996zG6ek9UvGwcCJao_hlDMlgbWWvJpONrs を入力して検索し、cCryptoGS を追加する。
// 2. 暗号化・復号化
//     サンプルを https://ramblings.mcpher.com/gassnippets2/cryptojs-libraries-for-google-apps-script/ から取得
//     myFunction(){} に書き込み、実行。

function myFunctionEncoding() {
  var cipher = new cCryptoGS.Cipher('this is my passphrase', 'aes');
  var encryptedMessage = cipher.encrypt ('this is my message to be encrypted');
  Logger.log (encryptedMessage);
}

function myFunctionDecoding(){
  var cipher = new cCryptoGS.Cipher('this is my passphrase', 'aes');
  var decryptedMessage = cipher.decrypt("U2FsdGVkX1/s1ieiU/V4WBux5anBTyis47rEOqDectVJny6ILd+oYbsAIfL4DAoVrkltEPB/MkCR/LSNF5QEgg==");
  Logger.log (decryptedMessage);
}
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?