c9-core/node_modules/c9/crypt.js

28 wiersze
689 B
JavaScript
Czysty Zwykły widok Historia

2015-02-10 19:41:24 +00:00
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)
);
};