/* * 모바일 회원 가입 */ @Override public String registerMobileAccount(RequestRegisterMobileAccount mobileAccount) { MobileVerification verification = mobileVerificationRepository.findByIdAndDeviceId( mobileAccount.getId(), mobileAccount.getDeviceId()); if (verification == null) { throw new EdiyaAPIException(APIError.REGISTRAION_ERROR_NOT_FOUND_REQUEST); } String[] userInfo = CryptoUtils.decryptRSA( verification.getPrivateKeyModulus(), verification.getPrivateKeyExponent(), mobileAccount.getCrypto()) .split(":"); if (userInfo.length != 3) { throw new EdiyaAPIException(APIError.REGISTRAION_ERROR_SYNTAX_ACCOUNT_INFO); } // TODO userName, userId, deviceId 중복 체크 // 사용자 정보 생성 String userId = CryptoUtils.generateUserId(); String secret = CryptoUtils.generateSecureRandom(); String name = userInfo[0]; String nick = userInfo[1]; String password = userInfo[2]; // 계정정보 저장 User user = new User(userId, name, nick, password); userRepository.save(user); // 단말기 정보 저장 DeviceSession session = new DeviceSession(userId, secret, verification); deviceSessionRepository.save(session); // 가입 요청 정보 삭제 mobileVerificationRepository.delete(verification); logger.info( "registerMobileAccount {} {} {} {}", user.getId(), user.getName(), user.getNick(), session.getDeviceId()); return Base64Utils.encodeToString(verification.getDeviceId().getBytes()) + ":" + Base64Utils.encodeToString(secret.getBytes()); }
/** * 将文件编码为BASE64字符串 * * <p>大文件慎用,可能会导致内存溢出 * * @param filename 文件绝对路径 * @return * @throws Exception */ public static String encodeFile(final String filename) throws IOException { byte[] bytes = file2bytes(filename); return Base64Utils.encodeToString(bytes); }