本文整理汇总了TypeScript中crypto-js.AES.encrypt方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AES.encrypt方法的具体用法?TypeScript AES.encrypt怎么用?TypeScript AES.encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crypto-js.AES
的用法示例。
在下文中一共展示了AES.encrypt方法的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: 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})
}
})
示例3: 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
}
}
示例4: 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)})
}
}
示例5: 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');
}
}
示例6:
router.get('/login', (request: Request, response: Response) => {
const { user, query } = request;
passport.authenticate('auth0', {
state:
user && query.change_email !== undefined
? AES.encrypt(
JSON.stringify({
old_user: request.user,
old_email: user.emails[0].value,
}),
SECRET
).toString()
: '',
} as any)(request, response);
});
示例7: phone_request
// Phone Verification
async function phone_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 phone_number = make_phonenumber_sane(req.body.phone_number, req.body.country_code)
console.log(phone_number)
let duplicate_user:any = await pendingUser.findOne({ phone_number })
let number_in_use = false
console.log(duplicate_user)
if(duplicate_user) number_in_use = duplicate_user.social_id !== found_user.social_id
if(await realUser.findOne({ phone_number }) || number_in_use || found_user.sms_verified ) return res.status(500).send({ message: 'The phone number is already getting used' })
if(await phoneCode.findOne({ user_id: found_user._id })) return res.status(500).send({message: 'You have already a pending sms-confirmation!'})
if(found_user.sms_verif_tries > 3) return res.status(500).send({message: 'Your requests for sms-verification went over the limit - please contact us on discord!'})
let random_code = crypto.randomBytes(2).toString('hex')
let response = await send_sms(phone_number, random_code)
let valid_number = process.env.REG_TESTNET === 'true' ? process.env.REG_TESTNET === 'true' : response.body.status !== '0'
console.log('sms res', response)
if(valid_number) {
const encryptedPhone = CryptoJS.AES.encrypt(phone_number, process.env.DECRYPT_KEY);
let phone_code:any = new phoneCode({ user_id: found_user._id, code: random_code, phone_number: encryptedPhone })
await phone_code.save()
found_user.sms_verif_tries += 1
await found_user.save()
res.status(200).send('Code has been send via SMS')
} else {
res.status(500).json({ message: filter_error_message(response.body.status)})
}
} catch (error) {
console.error(error)
res.status(500).json({ message: filter_error_message(error.message)})
}
}
示例8: encryptTemp
function encryptTemp(username, password) {
encryptedUsername = CryptoJS.AES.encrypt(username, os.hostname());
encryptedPassword = CryptoJS.AES.encrypt(password, os.hostname());
}
示例9: crypto
export function crypto(key: string, text: string): string {
const utf8 = CryptoJS.enc.Utf8.parse(text);
const enctext = CryptoJS.AES.encrypt(utf8, key);
return enctext.toString();
}
示例10: aesEncrypt
function aesEncrypt(text: string, secKey: string): string {
return CryptoJS.AES.encrypt(text,
CryptoJS.enc.Utf8.parse(secKey),
{iv: CryptoJS.enc.Utf8.parse('0102030405060708')}
).toString()
}