kopia lustrzana https://github.com/c9/core
28 wiersze
689 B
JavaScript
28 wiersze
689 B
JavaScript
|
var crypto = require("crypto");
|
||
|
|
||
|
exports.crypt = function(sessionId, secret) {
|
||
|
var cipher = crypto.createCipher("aes256", secret);
|
||
|
return (
|
||
|
cipher.update(sessionId, "ascii", "base64") +
|
||
|
cipher.final("base64")
|
||
|
).replace(/\=+$/, "");
|
||
|
};
|
||
|
|
||
|
exports.decrypt = function(encrypted, secret) {
|
||
|
var cipher = crypto.createDecipher("aes256", secret);
|
||
|
|
||
|
var data = [
|
||
|
cipher.update(encrypted, "base64", "ascii"),
|
||
|
cipher.final("ascii")
|
||
|
];
|
||
|
|
||
|
return data.join("").replace(/\=+$/, "");
|
||
|
};
|
||
|
|
||
|
exports.uid = function(length) {
|
||
|
return (require("crypto")
|
||
|
.randomBytes(length)
|
||
|
.toString("base64")
|
||
|
.slice(0, length)
|
||
|
);
|
||
|
};
|