本文整理匯總了TypeScript中crypto-js.AES類的典型用法代碼示例。如果您正苦於以下問題:TypeScript AES類的具體用法?TypeScript AES怎麽用?TypeScript AES使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了AES類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: encrypt
function encrypt(username, password) {
//OS.hostname() is the key.
//AES encryption
encryptedUsername = CryptoJS.AES.encrypt(username, os.hostname());
encryptedPassword = CryptoJS.AES.encrypt(password, os.hostname());
writetoJSON(encryptedUsername, encryptedPassword);
}
示例2: getPassword
function getPassword() {
var decryptedPasswordBytes = CryptoJS.AES.decrypt(
encryptedPassword.toString(),
os.hostname()
);
return decryptedPasswordBytes.toString(CryptoJS.enc.Utf8);
}
示例3: email_request
// EMAIL VERIFICATION
async function email_request(req, res, next) {
try {
let found_user:any = await pendingUser.findOne({ _id: req.body.user_id })
if(!found_user) return res.status(500).send({message: 'User not found'})
let duplicate_user:any = await pendingUser.findOne({ email: req.body.email })
let email_in_use = false
if(duplicate_user) email_in_use = duplicate_user.social_id !== found_user.social_id
if(await realUser.findOne({ email: req.body.email }) || email_in_use || found_user.email_verified ) return res.status(500).send({ message: 'The email adress is already getting used' })
let token:any = new emailToken({ user_id: found_user._id, token: crypto.randomBytes(16).toString('hex') })
await token.save()
found_user.email = CryptoJS.AES.encrypt(req.body.email, process.env.DECRYPT_KEY);
await found_user.save()
let confirmation_link = process.env.NODE_ENV === 'production' ? `https://signup.utopian.io` : `http://localhost:${process.env.REGISTRATION_FRONTEND_PORT}`
let transporter = nodemailer.createTransport({ host: 'smtp.gmail.com', port: 465, secure: true, auth: { user: process.env.GOOGLE_MAIL_ACCOUNT, pass: process.env.GOOGLE_MAIL_PASSWORD } })
let mailOptions = { from: process.env.GOOGLE_MAIL_ACCOUNT, to: req.body.email, subject: 'Utopian Email Confirmation', text: 'Hey there,\n\n' + `Please confirm your email for Utopian.io by clicking on this link: ${confirmation_link}/email/confirm/${token.token}` + '.\n' }
await transporter.sendMail(mailOptions)
res.status(200).send('A verification email has been sent to ' + found_user.email + '.')
} catch (error) {
console.error(error.message)
res.status(500).json({ message: filter_error_message(error.message)})
}
}
示例4: is_user_verified
request.get(request_api_user).query({access_token}).end(async (err, result) => {
let data = provider === 'github' ? result.body : JSON.parse(result.text)
let user:any = { id: data.id, email: data.email }
user.name = provider === 'github' ? data.login : data.name
user.verified = is_user_verified(provider, data)
if(provider === 'github' && !user.email) {
let resp_email = await request.get(EMAIL_API_GITHUB).query({access_token})
user.email = await get_primary_email(resp_email.body)
}
let found_user = await pendingUser.get(user.id)
const encryptedSocialEmail = CryptoJS.AES.encrypt(user.email, process.env.DECRYPT_KEY);
if(found_user) {
found_user.social_verified = user.verified
found_user.social_email = encryptedSocialEmail;
found_user.social_name = user.name
await found_user.save()
res.status(200).json({user: found_user, access_token})
} else {
let salt = generate_rnd_string(4)
user = await pendingUser.create({ social_name: user.name, social_id: user.id, social_verified: user.verified, social_email: encryptedSocialEmail, social_provider: provider, salt })
res.status(200).json({user, access_token})
}
})
示例5: create_new_user
export async function create_new_user(pending_user) {
try {
let { steem_account, email, phone_number, social_provider, social_name, social_id, social_verified } = pending_user;
const encryptedEmail = CryptoJS.AES.encrypt(email, process.env.DECRYPT_KEY);
let user:any = new realUser({ account: steem_account, email: encryptedEmail, test_net: process.env.REG_TESTNET === 'true' || false})
if(!user.social_data) user.social_data = []
user.social_data.push({ provider: social_provider, social_name, social_id, social_verified })
if(!user.last_passwords) user.last_passwords = []
user.last_passwords.push(pending_user.last_digits_password)
user.details.recoveryAccount = process.env.ACCOUNT_CREATOR
user.privacy = pending_user.privacy
user.tos = pending_user.tos
await user.save()
return user
} catch (error) {
console.error(error)
return false
}
}
示例6: getPasswordTemp
function getPasswordTemp() {
if(encryptedPassword === undefined){ //the user did not login, return null
return null;
}else {
var decryptedPasswordBytes = CryptoJS.AES.decrypt(encryptedPassword.toString(), os.hostname());
return decryptedPasswordBytes.toString(CryptoJS.enc.Utf8);
}
}
示例7: decrypto
export function decrypto(key: string, enctext: string): string | null {
const decrypted = CryptoJS.AES.decrypt(enctext, key);
let dectext = null;
if (decrypted.toString().length > 100) {
dectext = decrypted.toString(CryptoJS.enc.Utf8);
}
return dectext;
}
示例8: encrypt
/**
* Encrypts an object
* @param {Object} payload
* @returns {string}
*/
encrypt(payload: Object): string{
try{
return CryptoJS.AES.encrypt(JSON.stringify(payload), this.key)
.toString()
}catch (TypeError){
throw new Error('None or invalid encryption key specified');
}
}
示例9: getUsernameTemp
function getUsernameTemp() {
if (encryptedUsername === undefined){ // the user has not logged in, return null
return null;
}else {
var decryptedUsernameBytes = CryptoJS.AES.decrypt(encryptedUsername.toString(), os.hostname());
return decryptedUsernameBytes.toString(CryptoJS.enc.Utf8);
}
}
示例10: getUsername
function getUsername() {
if (encryptedUsername != null) {
var decryptedUsernameBytes = CryptoJS.AES.decrypt(
encryptedUsername.toString(),
os.hostname()
);
return decryptedUsernameBytes.toString(CryptoJS.enc.Utf8);
}
}