Javascript 谷歌应用程序脚本加密API

Javascript 谷歌应用程序脚本加密API,javascript,api,google-apps-script,encryption,Javascript,Api,Google Apps Script,Encryption,我正试图建立一个api与谷歌应用程序脚本,可以加密和解密字符串。下面是我的代码: function doPost(e){ const body = JSON.stringify(e.postData.contents);//your probably want JSON.parse here instead of stringify const FlemishGiant = body.FlemishGiant; const NetherlandDwarf = body.Netherl

我正试图建立一个api与谷歌应用程序脚本,可以加密和解密字符串。下面是我的代码:

function doPost(e){
  const body = JSON.stringify(e.postData.contents);//your probably want JSON.parse here instead of stringify
  const FlemishGiant = body.FlemishGiant;
  const NetherlandDwarf = body.NetherlandDwarf;
  const key = "$9681$%^&d";
  const cipher = new cCryptoGS.Cipher(key, 'aes');
  if (body.includes("FlemishGiant")) {
    var encryptedMessage = cipher.encrypt(FlemishGiant);
    var json = {
    'rabbitname':encryptedMessage,
}; 
  return ContentService.createTextOutput(JSON.stringify(json)).setMimeType(ContentService.MimeType.JSON); 

}
  if (body.includes("NetherlandDwarf")) {
   const decryptedMessage = cipher.decrypt(NetherlandDwarf);
    Logger.log(decryptedMessage);
    var json1 = {
      'rabbittype': decryptedMessage
  }; 
    return ContentService.createTextOutput(JSON.stringify(json1)).setMimeType(ContentService.MimeType.JSON);
}
else{
  return(error)
}

}

因此,当您发送API请求时,加密使用以下类型的主体:

{
"FlemishGiant":"STRING GOES HERE"
}
解密使用这个主体:

{
"NetherlandDwarf":"STRING GOES HERE"
}
我的google应用程序脚本使用cCryptoGS库

我主要在解密方面有问题。我希望解密后的文件能被退回。当我尝试一些东西时,它什么也不返回,其他时候它会给我一个typeerror,表示它无法读取未定义的属性“NetherlandDwarf”,NetherlandDwarf是body的属性


非常感谢,我希望我们能尽快找到答案

尝试放置
Logger.log(body)
const body=JSON.stringify(e.postData.contents)
和检查执行失败后,我不明白这会改变什么。这是一个调试工具。该错误表示未定义主体。是吗?如果您试图从另一个函数调用doPost(),但没有提供事件对象,那么这是行不通的。doPost和doGet是从部署的webapp端点调用的函数。主体已定义,佛兰芒巨人(加密)工作完美。