Pot.Arc4.prototype.encrypt

{Pot.Arc4} Pot.Arc4.prototype.encrypt ({String} text)

Pot.js で利用可能。 PotLite.js では利用できません。

文字列 text を Arc4 で暗号化します。

Arc4 アルゴリズムで 文字列 text を暗号化して返します。
結果の文字列は、ほとんどの場合 表示できない範囲の文字が含まれます。
表示したり、ASCII 値で取得したりする場合は Base64 などを利用ください。

現在の Pot.Arc4 インスタンス が返ります。

var arc4 = new Pot.Arc4('hoge');

// 暗号化
var cipherText = arc4.encrypt('Hello World!');
debug('cipherText = ' + cipherText); // 'cipherText = (...cipherText)'

// 復号化
var origText = arc4.decrypt(cipherText);
debug('origText = ' + origText); // 'origText = Hello World!'

encrypt は deferred というメソッドがあり、非同期で実行することが可能です。
非同期で実行することにより、巨大な文字列に対しても負荷を抑え実行することが可能です。

{Pot.Deferred} Pot.Arc4.prototype.encrypt.deferred ({String} text)

Arc4 アルゴリズムで 文字列 text を非同期で暗号化します。
暗号化された結果を引数に持つ Pot.Deferred インスタンス が返ります。
encrypt.deferred() で実行できます。
結果からは then() などによりチェインを繋げることができます。

encrypt.deferred.slow() のようにして速度の指定ができます。
指定できる名前は以下の表を参照ください。
デフォルトの速度は normal です。

値 / メソッド名 速度
limp 最も遅い
doze 遅い
slow 遅め
normal 通常
fast 速め
rapid 速い
ninja 最も速い

非同期実行の例:

var arc4 = new Pot.Arc4('hoge');

arc4.encrypt.deferred('Hello World!').then(function(cipherText) {
    debug('cipherText = ' + cipherText); // 'cipherText = (...cipherText)'
    return arc4.decrypt.deferred(cipherText).then(function(origText) {
        debug('origText = ' + origText); // 'origText = Hello World!'
    });
});