第10章 $fh.sec

$fh.sec(options, success, failure);

キーペアの生成およびデータの暗号化と暗号解除。

サポートされるプラットフォーム

  • JavaScript SDK

    • Cordova
    • Web Apps

詳細なバージョン情報については、Supported Configurations (英語) を参照してください。

10.1. 例

// Generate a new Key
var options = {
  "act": "keygen",
  "params": {
    "algorithm": "AES", // Only AES supported
    "keysize": "128" // 128 or 256
  }
};

$fh.sec(options, function(res) {
  // The algorithm used for the generation
  var algorithm = res.algorithm;

  // The generated key (hex format)
  var secretkey = res.secretkey;

  // The generated initial vector (hex format)
  var iv = res.iv;
}, function(code) {
  // Error code. One of:
  //  bad_act   : invalid action type
  //  no_params : params missing
  //  no_params_algorithm : missing algorithm in params
  console.error(code);
});


// Encrypt data
var options = {
  "act": "encrypt",
  "params": {
    // The data to be encrypted
    "plaintext": "Need a new page to start on",
    // The secret key used to do the encryption. (Hex format)
    "key": secretkey,
    // The algorithm used for encryption. Should be either "RSA" or "AES"
    "algorithm": "AES",
    // IV only required if algorithm is "AES"
    "iv": iv
  }
};
$fh.sec(options, function (res) {
  // The encrypted data (hex format)
  var ciphertext = res.ciphertext;
}, function (code) {
  // Error code. One of:
  //  bad_act   : invalid action type
  //  no_params : params missing
  //  no_params_algorithm : missing algorithm in params
  console.error(code);
});

// Decrypt data
var options = {
  "act": "encrypt",
  "params": {
    // The data to be decrypted
    "ciphertext": "dc87f02ae3fce8149d1e2b97a747581f8bc7c0c01b435a87ba56661b1ae",
    // The secret key used to do the decryption. (Hex format)
    "key": secretkey,
    // The algorithm used for decryption. Should be either "RSA" or "AES"
    "algorithm": "AES",
    // IV only required if algorithm is "AES"
    "iv": iv
  }
};
$fh.sec(options, function (res) {
  // The decrypted data (hex format)
  var plaintext = res.plaintext;
}, function (code) {
  // Error code. One of:
  //  bad_act   : invalid action type
  //  no_params : params missing
  //  no_params_algorithm : missing algorithm in params
  console.error(code);
});