本文整理汇总了TypeScript中crypto-js.SHA256函数的典型用法代码示例。如果您正苦于以下问题:TypeScript SHA256函数的具体用法?TypeScript SHA256怎么用?TypeScript SHA256使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SHA256函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addNewMember
/**
* @description
* <p>This method send a request to the backend of MaaS with the purpose
* to add one member to one company.</p>
* @param company_id {string} ID of the company
* @param token {string} Token of the user
* @param memberData {IAddMemberUser} New member data
* @returns {Promise<T>|Promise} The result or the error
*/
public addNewMember(
company_id : string,
token : string,
memberData : IAddMemberUser
) : Promise<Object> {
let encript1 : string = crypto.SHA256(
memberData.password,
"BugBusterSwe"
).toString();
memberData.password = crypto.SHA256(encript1, "MaaS").toString();
return new Promise(
function(resolve : (jsonObject : IAddMemberResponse) => void,
reject : (error : ActionError) => void) : void {
request
.post
("/api/companies/" + company_id + "/users")
.set("Accept", "application/json")
.set("x-access-token", token)
.send(memberData)
.end(function(error : Object, res : Response) : void {
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let addCompanyResponse : IAddMemberResponse =
res.body;
resolve(addCompanyResponse);
}
});
});
}
示例2: superAdminCreation
/**
* @description
* <p>This method send a request of super admin registration
* to the backend of MaaS.</p>
* @param data {ISupeAdminCreation}
* @param token {string}
* @returns {Promise<Object>|Promise} The result or the error
*/
public superAdminCreation(
data : ISupeAdminCreation,
token : string
) : Promise<Object> {
let encript1 : string = crypto.SHA256(
data.password,
"BugBusterSwe"
).toString();
data.password = crypto.SHA256(encript1, "MaaS").toString();
return new Promise(
function(
resolve : (jsonObject : ISuperAdminCreationResponse) => void,
reject : (error : ActionError) => void) : void {
request
.post
("/api/admin/superadmins")
.set("Accept", "application/json")
.set("x-access-token", token)
.send(data)
.end(function(error : Object, res : Response) : void {
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let userRegistrationResponse :
ISuperAdminCreationResponse = res.body;
resolve(userRegistrationResponse);
}
});
});
}
示例3: createUser
/**
* @api {post} api/companies/:company_id/users Create a new User
* @apiVersion 1.0.0
* @apiName createUser
* @apiGroup User
* @apiPermission OWNER
*
* @apiDescription Use this request to insert a new user in a stated
* company.
*
* @apiParam {String} company_id The Company's ID.
* @apiParam {String} user_id The ID of the logged user.
*
* @apiExample Example usage:
* curl \
* -H "Accept: application/json" \
* -H "x-access-token: {authToken}" \
* -X POST \
* -d '{"email": "prova@try.it, }' \
* http://maas.com/api/companies/5741/users
*
* @apiSuccess {string} _id The User's _id.
* @apiSuccess {string} email the email address of the user.
* @apiSuccess {string} level the level of the user.
*
* @apiError NoAccessRight Only authenticated Owners can access the data.
* @apiError CannotCreateTheUser It was impossible to create the user.
* @apiError ErrorSendingEmail Can't send the email
*
* @apiErrorExample Response (example):
* HTTP/1.1 400
* {
* "code" : "ECU-001",
* "error" : "Cannot create the user"
* }
*/
/**
* @description Create a new user for a specific company.
* @param request The express request.
* <a href="http://expressjs.com/en/api.html#req">See</a> the official
* documentation for more details.
* @param response The express response object.
* <a href="http://expressjs.com/en/api.html#res">See</a> the official
* documentation for more details.
*/
private createUser(request : express.Request,
response : express.Response) : void {
let userData : UserDocument = request.body;
userData.company = request.params.company_id;
let initial_pass : string = crypto.randomBytes(20).toString("base64");
let mailOptions : MailOptions = {
from: "service@maas.com",
to: userData.email,
subject: "MaaS registration",
text: "Hello and welcome in MaaS! \n" +
"You can start using our service from now!\n\n" +
"Below you can find your credentials: \n\n" +
"Email: " + userData.email + "\n" +
"Password: " + initial_pass + "\n\n" +
"Best regards, \n" +
"The MaaS team",
html: "",
};
let encript1 : string = cryptoFE.SHA256(
initial_pass, "BugBusterSwe").toString();
let encryptedPassword : string = cryptoFE.SHA256(
encript1, "MaaS").toString();
userData.password = encryptedPassword;
mailSender(mailOptions, function (error : Object) : void {
if (!error) {
user
.create(userData)
.then(function (data : UserDocument) : void {
response
.status(200)
.json(data);
}, function () : void {
response
.status(400)
.json({
code: "ECU-001",
message: "Cannot create the user."
});
});
} else {
response
.status(400)
.json({
code: "ECM-001",
message: "Error sending Email."
});
}
});
}
示例4: function
RouterFacade.get("/setup", function (request : express.Request,
response : express.Response) : void {
let encript1 : string = crypto.SHA256(
"123456ciao", "BugBusterSwe").toString();
let encryptedPassword : string = crypto.SHA256(
encript1, "MaaS").toString();
user.addSuperAdmin({
email: "bug@prova.it",
password: encryptedPassword
}).then(function (data : Object) : void {
response.json(data);
}, function (error : Object) : void {
response.json(error);
});
});
示例5: addCompany
/**
* @description
* <p>This method send a request to the backend of MaaS with the purpose
* to add one company.</p>
* @param user {IAddCompanyUser} Data of the owner of the company
* @param company {ICompanyName} Company data
* @param token {string} Token of the user
* @returns {Promise<T>|Promise} the result or the error
*/
public addCompany(user : IAddCompanyUser,
company : ICompanyName) : Promise<Object> {
let encript1 : string = crypto.SHA256(
user.password, "BugBusterSwe").toString();
user.password = crypto.SHA256(encript1, "MaaS").toString();
return new Promise(
function(resolve : (jsonObject : IAddCompanyResponse ) => void,
reject : (error : ActionError) => void) : void {
request
.post("/api/companies")
.send({user, company})
.end(function(error : Object, res : Response) : void {
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let addCompanyResponse : IAddCompanyResponse = res.body;
resolve(addCompanyResponse);
}
});
})
}
示例6: loginLogbook
public loginLogbook(emailAddress: string, password: string) : Promise<JsonWebTokenModel> {
let body = {
emailAddress: emailAddress,
passwordSHA256Hash: crypto.SHA256(password).toString(crypto.enc.Base64),
};
return this.httpClient
.createRequest("Authentication/Login/Logbook")
.asPost()
.withContent(body)
.send()
.then(response => response.content)
.catch(response => Promise.reject(response.content.message));
}
示例7: updateUserPassword
/**
* @description
* <p>This method send a request of update of password
* to the backend of MaaS.</p>
* @param data {IUpdateUserPassword}
* @returns {Promise<T>|Promise} The result or the error
*/
public updateUserPassword(data : IUpdateUserPassword) : Promise<Object> {
let encript1NP : string = crypto.SHA256(
data.newPassword, "BugBusterSwe").toString();
let encryptedPasswordNP : string = crypto.SHA256(
encript1NP, "MaaS").toString();
let encript1OP : string = crypto.SHA256(
data.password, "BugBusterSwe").toString();
let encryptedPasswordOP : string = crypto.SHA256(
encript1OP, "MaaS").toString();
return new Promise(
function(
resolve : (jsonObject : IUpdate) => void,
reject : (error : ActionError) => void) : void {
request
.put("/api/companies/" + data.company_id + "/users/"
+ data._id + "/credentials")
.send(
{ username: data.username,
password : encryptedPasswordOP,
newUsername: data.newUsername,
newPassword: encryptedPasswordNP
})
.set("Accept", "application/json")
.set("x-access-token", data.token)
.end(function(error : Object, res : Response) : void {
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let updateUserPasswordResponse :
IUpdate = res.body;
resolve(updateUserPasswordResponse);
}
});
});
}
示例8: login
/**
* @description This method send a request of login to the backend of MaaS.
* @param email {string} Email of the user
* @param password {string} Password of the user
* @returns {Promise<T>|Promise} The result or the error
*/
public login(email : string, password : string) : Promise<Object> {
let encript1 : string = crypto.SHA256(
password, "BugBusterSwe").toString();
let encryptedPassword : string = crypto.SHA256(
encript1, "MaaS").toString();
return new Promise(
function(
resolve : (jsonObj : ILoginResponse) => void,
reject : (err : ActionError) => void) : void {
request.post("/api/login")
.send({email : email, password : encryptedPassword,
grant_type : "password"})
.set("Content-Type", "application/json")
.end(function(error : Object, res : Response) : void{
if (error) {
let actionError : ActionError = res.body;
reject(actionError);
} else {
let loginResponse : ILoginResponse = res.body;
resolve(loginResponse);
}
});
});
}
示例9: register
public register(emailAddress: string, password: string, language: string) : Promise<void> {
let body = {
emailAddress: emailAddress,
passwordSHA256Hash: crypto.SHA256(password).toString(crypto.enc.Base64),
preferredLanguage: language,
};
return this.httpClient
.createRequest("Authentication/Register")
.asPost()
.withContent(body)
.send()
.then(response => null)
.catch(response => Promise.reject(response.content.message));
}
示例10: createToken
private async createToken(user: MoAdmins): Promise<string> {
const token = SHA256(`${user.id} ${user.login} ${Math.random()} ${new Date().toISOString}`).toString();
// Remove old auth key, just in case it's in DB
await Logout.cleanAuth(user);
const usersAuth = new MoUsersAuth();
usersAuth.timestamp = new Date();
usersAuth.token = token;
usersAuth.user = user;
await getConnection().getRepository(MoUsersAuth).save(usersAuth);
return token;
}