15.1 字符串加密

字符串编码加密, openssl 包提供了 sha1 函数 29

library(openssl)
encode_mobile <- function(phone_number) paste("*", paste(toupper(sha1(sha1(charToRaw(paste(phone_number, "$1$mobile$", sep = ""))))), collapse = ""), sep = "")
# 随意模拟两个手机号
mobile_vec <- c("18601013453", "13811674545")
sapply(mobile_vec, encode_mobile)
##                                 18601013453 
## "*B1D46D1D62C7280137F0E14249EE500865247B7B" 
##                                 13811674545 
## "*0554DA6E403491F58F1567DF2EDEB19186B77173"