提交 37d02990 编写于 作者: qq_53854309's avatar qq_53854309

Initial commit

上级
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ]; then
if [ -f /usr/local/etc/mavenrc ]; then
. /usr/local/etc/mavenrc
fi
if [ -f /etc/mavenrc ]; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ]; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false
darwin=false
mingw=false
case "$(uname)" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true ;;
Darwin*)
darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="$(/usr/libexec/java_home)"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ]; then
if [ -r /etc/gentoo-release ]; then
JAVA_HOME=$(java-config --jre-home)
fi
fi
if [ -z "$M2_HOME" ]; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ]; do
ls=$(ls -ld "$PRG")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' >/dev/null; then
PRG="$link"
else
PRG="$(dirname "$PRG")/$link"
fi
done
saveddir=$(pwd)
M2_HOME=$(dirname "$PRG")/..
# make it fully qualified
M2_HOME=$(cd "$M2_HOME" && pwd)
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=$(cygpath --unix "$M2_HOME")
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
[ -n "$CLASSPATH" ] &&
CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw; then
[ -n "$M2_HOME" ] &&
M2_HOME="$( (
cd "$M2_HOME"
pwd
))"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="$( (
cd "$JAVA_HOME"
pwd
))"
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="$(which javac)"
if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=$(which readlink)
if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then
if $darwin; then
javaHome="$(dirname \"$javaExecutable\")"
javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac"
else
javaExecutable="$(readlink -f \"$javaExecutable\")"
fi
javaHome="$(dirname \"$javaExecutable\")"
javaHome=$(expr "$javaHome" : '\(.*\)/bin')
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ]; then
if [ -n "$JAVA_HOME" ]; then
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="$(
\unset -f command
\command -v java
)"
fi
fi
if [ ! -x "$JAVACMD" ]; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ]; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]; then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ]; do
if [ -d "$wdir"/.mvn ]; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=$(
cd "$wdir/.."
pwd
)
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' <"$1")"
fi
}
BASE_DIR=$(find_maven_basedir "$(pwd)")
if [ -z "$BASE_DIR" ]; then
exit 1
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
else
jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
fi
while IFS="=" read key value; do
case "$key" in wrapperUrl)
jarUrl="$value"
break
;;
esac
done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
fi
if command -v wget >/dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
else
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
fi
elif command -v curl >/dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f
else
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaClass=$(cygpath --path --windows "$javaClass")
fi
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=$(cygpath --path --windows "$M2_HOME")
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
[ -n "$CLASSPATH" ] &&
CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %WRAPPER_JAR% ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%"=="on" pause
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
cmd /C exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.10</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hao</groupId>
<artifactId>digitalsignature</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>digitalsignature</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.7.10</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.hao.digitalsignature;
import org.mapstruct.MapperConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.hao.digitalsignature.mapper")
public class DigitalsignatureApplication {
public static void main(String[] args) {
SpringApplication.run(DigitalsignatureApplication.class, args);
}
}
package com.hao.digitalsignature.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//com包下所有api都交给swagger2管理
.apis(RequestHandlerSelectors.basePackage("com"))
.paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("演示项目api")
.description("学习swagger2的演示")
.version("1.0")
.build();
}
}
\ No newline at end of file
package com.hao.digitalsignature.config;
import com.hao.digitalsignature.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/user/**");
}
}
package com.hao.digitalsignature.controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.SocketException;
import java.net.URLEncoder;
import java.util.UUID;
@RequestMapping("/file")
@RestController
public class FileDealController {
@RequestMapping(value = "upload")
public String upload(@RequestParam("file") MultipartFile pic) throws SocketException, IOException {
String newName = "";
if (null!=pic&&pic.getSize()>0){//上传了图片
//获取文件的原始名称
String oname=pic.getOriginalFilename();//例如:121.jpg
//获取文件的后缀名
String suffix=oname.substring(oname.lastIndexOf(".")); // .jpg
//新的文件名
newName= UUID.randomUUID()+suffix;
try {
// 获取当前项目下路径:方式一
File file = new File("");
String filePath = file.getCanonicalPath();
// pic.transferTo(new File("../pic",newName));
pic.transferTo(new File(filePath+"\\src\\main\\resources\\static\\img",newName));
} catch (IOException e) {
e.printStackTrace();
}
}
return newName;
}
/**
* 下载
* @param request
* @param response
* @param fileName
* @return
*/
@RequestMapping(value = "download")
public static void downFile(@RequestBody String fileName, HttpServletRequest request,
HttpServletResponse response) {
// 得到要下载的文件名
//String fileName = filename.substring(4);
fileName = fileName.substring(0,fileName.length()-1);
// fileName="666.jpg";
try {
File filep = new File("");
String filePath = filep.getCanonicalPath();
// 上传位置
String fileSaveRootPath =filePath+"\\src\\main\\resources\\static\\img";
System.out.println(fileSaveRootPath + "\\" + fileName);
// 得到要下载的文件
File file = new File(fileSaveRootPath + "\\" + fileName);
// 如果文件不存在
if (!file.exists()) {
request.setAttribute("message", "您要下载的资源已被删除!!");
System.out.println("您要下载的资源已被删除!!");
return ;
}
// 处理文件名
String realname = fileName.substring(fileName.indexOf("_") + 1);
// 设置响应头,控制浏览器下载该文件
// response.setContentType("image/png");
response.setHeader("Content-Disposition", "attachment;filename="
+ URLEncoder.encode(realname, "UTF-8"));
// 读取要下载的文件,保存到文件输入流
FileInputStream in = new FileInputStream(fileSaveRootPath + "\\" + fileName);
// response.setHeader("Location",);
// 创建输出流
OutputStream out = response.getOutputStream();
// 创建缓冲区
byte buffer[] = new byte[1024];
int len = 0;
// 循环将输入流中的内容读取到缓冲区当中
while ((len = in.read(buffer)) > 0) {
// 输出缓冲区的内容到浏览器,实现文件下载
out.write(buffer, 0, len);
}
// 关闭文件输入流
in.close();
// 关闭输出流
out.close();
} catch (Exception e) {
System.out.println("error");
}
}
}
package com.hao.digitalsignature.controller;
import com.hao.digitalsignature.encryption.DSASign;
import com.hao.digitalsignature.encryption.RSAEncrypt;
import com.hao.digitalsignature.entity.User;
import com.hao.digitalsignature.mapper.UserMapper;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.hao.digitalsignature.entity.Files;
import com.hao.digitalsignature.mapper.FileMapper;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
@RestController
public class FilesController {
@Autowired
private FileMapper fileMapper;
// @PostMapping("/upload")
// public String up(String name, MultipartFile photo, HttpServletRequest request) throws IOException{
// //自定文件名
// System.out.println(name);
// //文件原名
// System.out.println(photo.getOriginalFilename());
// //文件类型
// System.out.println(photo.getContentType());
//
// String path=request.getServletContext().getRealPath("/upload/");
// System.out.println(path);
// saveFile(photo,path);
// return "上传成功";
// }
//
// public void saveFile(MultipartFile photo,String path) throws IOException{
// File dir = new File(path);
// if (!dir.exists()){
// dir.mkdir();
// }
// File file = new File(path+photo.getOriginalFilename());
// photo.transferTo(file);
// }
@PutMapping("/file/update")
public String update(int id,String name){
Files file = fileMapper.selectById(id);
if (file!=null){
file.setPicture_name(name);
fileMapper.updateById(file);
return "success";
}
else
return "fail";
}
@PostMapping("/file/save")
public String save(@RequestBody Files file){
System.out.println(file);
BigInteger back[]=new BigInteger[2];
int j=0;
Base64 base64 = new Base64();
DSASign dsa = new DSASign();
dsa.initKeys();
//要签名的数据,传入AES加密后的内容
String message = file.getPicture_realname();
System.out.println("签名的数据:"+message);
BigInteger sig[] = dsa.signature(message.getBytes());
String dig=sig[0]+";"+sig[1]+";"+dsa._hashInZq(message.getBytes());
file.setDig(dig);
int i = fileMapper.insert(file);
if (i>0)
return "success";
else
return "fail";
}
@GetMapping("/file/findAll")
public List<Files> find(){
return fileMapper.selectList(null);
}
}
package com.hao.digitalsignature.controller;
import com.hao.digitalsignature.entity.User;
import com.hao.digitalsignature.mapper.UserMapper;
import com.sun.org.apache.xpath.internal.objects.XString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class UserController {
@Autowired
private UserMapper userMapper;
// @GetMapping("/user/{id}")
// public String getUserById(@PathVariable int id){
// System.out.println(id);
// return "获取用户信息";
// }
// @PostMapping
// public String save(User user){return "添加";}
// @PutMapping
// public String update(User user){return "更新";}
// @DeleteMapping
// public String deleteById(@PathVariable int id){
// System.out.println(id);
// return "删除";
// }
@GetMapping("/user/findAll")
public List<User> find(){
return userMapper.selectAllUserAndFiles();
}
@GetMapping("/user/allUser")
public List query() {
List<User> list = userMapper.selectList(null);
System.out.println(list);
return list;
}
@PostMapping("/user/save")
public String save(User user){
int i = userMapper.insert(user);
if (i>0)
return "success";
else
return "fail";
}
@PutMapping("/user/update")
public String update(int id,String name){
User user = userMapper.selectById(id);
if (user!=null){
user.setUser_name(name);
userMapper.updateById(user);
return "success";
}
else
return "fail";
}
@DeleteMapping("/user/delete")
public String delete(int id){
int i= userMapper.deleteById(id);
if (i>0)
return "success";
else
return "fail";
}
}
package com.hao.digitalsignature.encryption;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.lang3.StringUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* @Title: AESUtils.java
* @Package com.fendo.MD5
* @Description: TODO
* @author fendo
* @date 2017年9月11日 下午5:48:17
* @version V1.0
*/
public class AES {
private static final String encodeRules = "fendo";
/**
* 加密
* 1.构造密钥生成器
* 2.根据ecnodeRules规则初始化密钥生成器
* 3.产生密钥
* 4.创建和初始化密码器
* 5.内容加密
* 6.返回字符串
*/
public static String AESEncode(String content) {
try {
//1.构造密钥生成器,指定为AES算法,不区分大小写
KeyGenerator keygen = KeyGenerator.getInstance("AES");
//2.根据ecnodeRules规则初始化密钥生成器
//生成一个128位的随机源,根据传入的字节数组
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(encodeRules.getBytes());
keygen.init(128, random);
//3.产生原始对称密钥
SecretKey original_key = keygen.generateKey();
//4.获得原始对称密钥的字节数组
byte[] raw = original_key.getEncoded();
//5.根据字节数组生成AES密钥
SecretKey key = new SecretKeySpec(raw, "AES");
//6.根据指定算法AES自成密码器
Cipher cipher = Cipher.getInstance("AES");
//7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密解密(Decrypt_mode)操作,第二个参数为使用的KEY
cipher.init(Cipher.ENCRYPT_MODE, key);
//8.获取加密内容的字节数组(这里要设置为utf-8)不然内容中如果有中文和英文混合中文就会解密为乱码
byte[] byte_encode = content.getBytes("utf-8");
//9.根据密码器的初始化方式--加密:将数据加密
byte[] byte_AES = cipher.doFinal(byte_encode);
//10.将加密后的数据转换为字符串
//这里用Base64Encoder中会找不到包
//解决办法:
//在项目的Build path中先移除JRE System Library,再添加库JRE System Library,重新编译后就一切正常了。
String AES_encode = new String(new BASE64Encoder().encode(byte_AES));
//11.将字符串返回
return AES_encode;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//如果有错就返加nulll
return null;
}
/**
* AES加密
* @param content 待加密的内容
* @param encryptKey 加密密钥
* @return 加密后的byte[]
* @throws Exception
*/
public static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom(encryptKey.getBytes()));
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
return cipher.doFinal(content.getBytes("utf-8"));
}
/**
* 解密
* 解密过程:
* 1.同加密1-4步
* 2.将加密后的字符串反纺成byte[]数组
* 3.将加密内容解密
*/
public static String AESDecode(String content) {
try {
//1.构造密钥生成器,指定为AES算法,不区分大小写
KeyGenerator keygen = KeyGenerator.getInstance("AES");
//2.根据ecnodeRules规则初始化密钥生成器
//生成一个128位的随机源,根据传入的字节数组
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(encodeRules.getBytes());
keygen.init(128, random);
//3.产生原始对称密钥
SecretKey original_key = keygen.generateKey();
//4.获得原始对称密钥的字节数组
byte[] raw = original_key.getEncoded();
//5.根据字节数组生成AES密钥
SecretKey key = new SecretKeySpec(raw, "AES");
//6.根据指定算法AES自成密码器
Cipher cipher = Cipher.getInstance("AES");
//7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密(Decrypt_mode)操作,第二个参数为使用的KEY
cipher.init(Cipher.DECRYPT_MODE, key);
//8.将加密并编码后的内容解码成字节数组
byte[] byte_content = new BASE64Decoder().decodeBuffer(content);
/*
* 解密
*/
byte[] byte_decode = cipher.doFinal(byte_content);
String AES_decode = new String(byte_decode, "utf-8");
return AES_decode;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
//如果有错就返加nulll
return null;
}
/**
* AES解密
* @param encryptBytes 待解密的byte[]
* @param decryptKey 解密密钥
* @return 解密后的String
* @throws Exception
*/
public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom(decryptKey.getBytes()));
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
byte[] decryptBytes = cipher.doFinal(encryptBytes);
return new String(decryptBytes);
}
/**
* base 64 加密
* @param bytes 待编码的byte[]
* @return 编码后的base 64 code
*/
public static String base64Encode(byte[] bytes){
return new BASE64Encoder().encode(bytes);
}
/**
* base 64 解密
* @param base64Code 待解码的base 64 code
* @return 解码后的byte[]
* @throws Exception
*/
public static byte[] base64Decode(String base64Code) throws Exception{
return StringUtils.isEmpty(base64Code) ? null : new BASE64Decoder().decodeBuffer(base64Code);
}
/**
* 将base 64 code AES解密
* @param encryptStr 待解密的base 64 code
* @param decryptKey 解密密钥
* @return 解密后的string
* @throws Exception
*/
public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception {
return StringUtils.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey);
}
/**
* AES加密为base 64 code
* @param content 待加密的内容
* @param encryptKey 加密密钥
* @return 加密后的base 64 code
* @throws Exception
*/
public static String aesEncrypt(String content, String encryptKey) throws Exception {
return base64Encode(aesEncryptToBytes(content, encryptKey));
}
public static void main(String[] args) {
String[] keys = {
"", "13693824197789382917025643020348151872"
};
System.out.println("key | AESEncode | AESDecode");
for (String key : keys) {
System.out.print("key:"+key + " | ");
String encryptString = AESEncode(key);
System.out.print(encryptString + " | ");
String decryptString = AESDecode(encryptString);
System.out.println(decryptString);
}
}
}
\ No newline at end of file
package com.hao.digitalsignature.encryption;
import org.apache.catalina.security.SecurityUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.security.SecureRandom;
import org.apache.commons.lang3.StringUtils;
/**
* AES加密解密
*/
public class AES1 {
private static final Logger logger = LoggerFactory.getLogger(SecurityUtil.class);
private static final String ENCODING = "UTF-8";
private static final String PASSWORD = "388f31778f8d7b227170f6ef67028e26"; // 加密秘钥
/**
* AES加密
* @param content 明文
* @return 密文
*/
public static String encryptAES(String content) throws Exception {
if (StringUtils.isEmpty(content)) {
throw new Exception("明文不能为空!");
}
byte[] encryptResult = encrypt(content, PASSWORD);
String encryptResultStr = parseByte2HexStr(encryptResult);
// BASE64位加密
encryptResultStr = ebotongEncrypto(encryptResultStr);
return encryptResultStr;
}
/**
* AES解密
* @param encryptResultStr 密文
* @return 明文
*/
public static String decryptAES(String encryptResultStr) throws Exception {
if (StringUtils.isEmpty(encryptResultStr)) {
throw new Exception("密文不能为空");
}
// BASE64位解密
try {
String decrpt = ebotongDecrypto(encryptResultStr);
byte[] decryptFrom = parseHexStr2Byte(decrpt);
byte[] decryptResult = decrypt(decryptFrom, PASSWORD);
return new String(decryptResult);
} catch (Exception e) { // 当密文不规范时会报错,可忽略,但调用的地方需要考虑
return null;
}
}
/**
* 加密字符串
*/
private static String ebotongEncrypto(String str) {
BASE64Encoder base64encoder = new BASE64Encoder();
String result = str;
if (str != null && str.length() > 0) {
try {
byte[] encodeByte = str.getBytes(ENCODING);
result = base64encoder.encode(encodeByte);
} catch (Exception e) {
e.printStackTrace();
}
}
// base64加密超过一定长度会自动换行 需要去除换行符
return result.replaceAll("\r\n", "").replaceAll("\r", "").replaceAll("\n", "");
}
/**
* 解密字符串
*/
private static String ebotongDecrypto(String str) {
BASE64Decoder base64decoder = new BASE64Decoder();
try {
byte[] encodeByte = base64decoder.decodeBuffer(str);
return new String(encodeByte);
} catch (IOException e) {
logger.error("IO 异常",e);
return str;
}
}
/**
* 加密
* @param content 需要加密的内容
* @param password 加密密码
* @return
*/
private static byte[] encrypt(String content, String password) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
// 注意这句是关键,防止linux下 随机生成key。用其他方式在Windows上正常,但Linux上会有问题
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(password.getBytes());
kgen.init(128, secureRandom);
// kgen.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
byte[] byteContent = content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化
byte[] result = cipher.doFinal(byteContent);
return result; // 加密
} catch (Exception e) {
logger.error("加密异常", e);
}
return null;
}
/**
* 解密
* @param content 待解密内容
* @param password 解密密钥
* @return
*/
private static byte[] decrypt(byte[] content, String password) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
// 防止linux下 随机生成key
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(password.getBytes());
kgen.init(128, secureRandom);
// kgen.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
byte[] result = cipher.doFinal(content);
return result; // 加密
} catch (Exception e) {
logger.error("解密异常", e);
}
return null;
}
/**
* 将二进制转换成16进制
* @param buf
* @return
*/
private static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 将16进制转换为二进制
* @param hexStr
* @return
*/
private static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
public static void main(String[] args) throws Exception {
test();
}
/**
* 测试
*/
private static void test() throws Exception {
System.out.println("加密解密");
String content = "7424862e-ec4b-455c-95f1-f7f4cdcf3588";
System.out.println("原内容为:" + content);
String encryContent = encryptAES(content);
System.out.println("加密后的内容为:" + encryContent);
String decryContent = decryptAES(encryContent);
System.out.println("解密后的内容为:" + decryContent);
}
}
\ No newline at end of file
package com.hao.digitalsignature.encryption;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class AESmiyao {
public static void main(String[] args) {
getKey();
// getKeyByPass();
}
/**
* 随机生成秘钥
*/
public static void getKey() {
try {
KeyGenerator kg = KeyGenerator.getInstance("AES");
kg.init(128);
//要生成多少位,只需要修改这里即可128, 192或256
SecretKey sk = kg.generateKey();
byte[] b = sk.getEncoded();
String s = byteToHexString(b);
System.out.println(s);
System.out.println("十六进制密钥长度为"+s.length());
System.out.println("二进制密钥的长度为"+s.length()*4);
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
System.out.println("没有此算法。");
}
}
/**
* 使用指定的字符串生成秘钥
*/
// public static void getKeyByPass() {
// //生成秘钥
// String password="testkey";
// try {
// KeyGenerator kg = KeyGenerator.getInstance("AES");
// // kg.init(128);//要生成多少位,只需要修改这里即可128, 192或256
// //SecureRandom是生成安全随机数序列,password.getBytes()是种子,只要种子相同,序列就一样,所以生成的秘钥就一样。
// kg.init(128, new SecureRandom(password.getBytes()));
// SecretKey sk = kg.generateKey();
// byte[] b = sk.getEncoded();
// String s = byteToHexString(b);
// System.out.println(s);
// System.out.println("十六进制密钥长度为"+s.length());
// System.out.println("二进制密钥的长度为"+s.length()*4);
// }
// catch (NoSuchAlgorithmException e) {
// e.printStackTrace();
// System.out.println("没有此算法。");
// }
// }
/**
* byte数组转化为16进制字符串
* @param bytes
* @return
*/
public static String byteToHexString(byte[] bytes) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
String strHex=Integer.toHexString(bytes[i]);
if(strHex.length() > 3) {
sb.append(strHex.substring(6));
} else {
if(strHex.length() < 2) {
sb.append("0" + strHex);
} else {
sb.append(strHex);
}
}
}
return sb.toString();
}
}
package com.hao.digitalsignature.encryption;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.sql.SQLOutput;
import com.hao.digitalsignature.encryption.RSAEncrypt;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
public class DSASign {
public BigInteger p,q,g;
public BigInteger x,y;
//160位随机数
public BigInteger _randomInZq(){
BigInteger r= null;
do {
r = new BigInteger(160, new SecureRandom());
}while(r.compareTo(q) >=0);
return r;
}
//SHA1 Hasn函数
public BigInteger _hashInZq(byte m[]){
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
md.update(m);
byte b[] = new byte[17];
System.arraycopy(md.digest(), 0, b, 1, 16);
return new BigInteger(b);
}catch (NoSuchAlgorithmException e){
System.out.print("This cannot happen!");
}
return null;
}
//生成公钥私钥
public void initKeys(){
q = new BigInteger(160, 100, new SecureRandom());
// 判定100%为素数
do {
BigInteger t = new BigInteger(512, new SecureRandom());
p = t.multiply(q).add(BigInteger.ONE);
}while(!p.isProbablePrime(100));
BigInteger h = _randomInZq();
g = h.modPow(p.subtract(BigInteger.ONE).divide(q), p);
x = _randomInZq();
y = g.modPow(x, p);
System.out.println("p : " + p);
System.out.println("q : " + q);
System.out.println("g : " + g);
System.out.println("发送方私钥x : " + x);
System.out.println("发送方公钥y : " + y);
}
//产生签名
public BigInteger[] signature(byte m[]){
BigInteger k = _randomInZq();
BigInteger sig[] = new BigInteger[2];
//得到r
sig[0] = g.modPow(k, p).mod(q);
//得到S
sig[1] = _hashInZq(m).add(x.multiply(sig[0])).mod(q)
.multiply(k.modInverse(q)).mod(q);
return sig;
}
//验证
public boolean verify(byte m[], BigInteger sig[]){
BigInteger w = sig[1].modInverse(q);
BigInteger u1 = _hashInZq(m).multiply(w).mod(q);
BigInteger u2 = sig[0].multiply(w).mod(q);
BigInteger v = g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q);
System.out.println("验证:");
System.out.println("v = " + v);
System.out.println("r = " + sig[0]);
return v.compareTo(sig[0]) == 0;
}
public static void main(String args[]) throws Exception {
String publicPath = "C:\\Users\\10908"; //公匙存放位置
String privatePath = "C:\\Users\\10908"; //私匙存放位置
BigInteger back[]=new BigInteger[2];
int j=0;
Base64 base64 = new Base64();
DSASign dsa = new DSASign();
//生成公钥和私钥
dsa.initKeys();
System.out.println("");
//要签名的数据,传入AES加密后的内容
String message = "NUJCQkJEQjRCRDBFODMwRTJCODkyOTQ1N0Y4NkEyNzU=";
System.out.println("签名的数据:"+message);
BigInteger sig[] = dsa.signature(message.getBytes());
//消息摘要
System.out.println("消息摘要:"+dsa._hashInZq(message.getBytes())+"\n");
//对消息摘要进行签名得到r和s,在使用RSA进行加密并发送
for (int i =0;i< sig.length;i++){
System.out.println("签名:"+sig[i].toString());
back[i]= new BigInteger(RSAEncrypt.RSA(sig[i].toString()));
}
System.out.println("\n需要解密的信息:"+back[0]);
System.out.println(" "+back[1]);
System.out.println("验证结果:" + dsa.verify(message.getBytes(),back) );
}
}
package com.hao.digitalsignature.encryption;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import sun.misc.BASE64Decoder;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.*;
import java.math.BigInteger;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
public class RSAEncrypt {
/**
* 字节数据转字符串专用集合
*/
private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private static final String PRIVATE_KEY = "\\pkcs8_rsa_sk.pem";
private static final String PUBLIC_KEY = "\\rsa_pk.pem";
/**
* 随机生成密钥对
*/
public static void genKeyPair(String filePath) {
// KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
KeyPairGenerator keyPairGen = null;
try {
keyPairGen = KeyPairGenerator.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// 初始化密钥对生成器,密钥大小为96-1024位
keyPairGen.initialize(1024, new SecureRandom());
// 生成一个密钥对,保存在keyPair中
KeyPair keyPair = keyPairGen.generateKeyPair();
// 得到私钥
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
// 得到公钥
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
try {
// 得到公钥字符串
Base64 base64 = new Base64();
String publicKeyString = new String(base64.encode(publicKey.getEncoded()));
// 得到私钥字符串
String privateKeyString = new String(base64.encode(privateKey.getEncoded()));
// 将密钥对写入到文件
FileWriter pubfw = new FileWriter(filePath + PUBLIC_KEY);
FileWriter prifw = new FileWriter(filePath + PRIVATE_KEY);
BufferedWriter pubbw = new BufferedWriter(pubfw);
BufferedWriter pribw = new BufferedWriter(prifw);
pubbw.write(publicKeyString);
pribw.write(privateKeyString);
pubbw.flush();
pubbw.close();
pubfw.close();
pribw.flush();
pribw.close();
prifw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 从文件中输入流中加载公钥
*
* @param path 公钥输入流
* @throws Exception 加载公钥时产生的异常
*/
public static String loadPublicKeyByFile(String path) throws Exception {
try {
BufferedReader br = new BufferedReader(new FileReader(path
+ PUBLIC_KEY));
String readLine = null;
StringBuilder sb = new StringBuilder();
while ((readLine = br.readLine()) != null) {
if (readLine.charAt(0) == '-') {
continue;
} else {
sb.append(readLine);
sb.append('\r');
}
}
br.close();
return sb.toString();
} catch (IOException e) {
throw new Exception("公钥数据流读取错误");
} catch (NullPointerException e) {
throw new Exception("公钥输入流为空");
}
}
/**
* 从字符串中加载公钥
*
* @param publicKeyStr 公钥数据字符串
* @throws Exception 加载公钥时产生的异常
*/
public static RSAPublicKey loadPublicKeyByStr(String publicKeyStr)
throws Exception {
try {
BASE64Decoder base64 = new BASE64Decoder();
byte[] buffer = base64.decodeBuffer(publicKeyStr);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(buffer);
return (RSAPublicKey) keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此算法");
} catch (InvalidKeySpecException e) {
throw new Exception("公钥非法");
} catch (NullPointerException e) {
throw new Exception("公钥数据为空");
}
}
/**
* 从文件中加载私钥
*
* @param path 私钥文件名
* @return 是否成功
* @throws Exception
*/
public static String loadPrivateKeyByFile(String path) throws Exception {
try {
BufferedReader br = new BufferedReader(new FileReader(path
+ PRIVATE_KEY));
String readLine = null;
StringBuilder sb = new StringBuilder();
while ((readLine = br.readLine()) != null) {
if (readLine.charAt(0) == '-') {
continue;
} else {
sb.append(readLine);
sb.append('\r');
}
}
br.close();
return sb.toString();
} catch (IOException e) {
throw new Exception("私钥数据读取错误");
} catch (NullPointerException e) {
throw new Exception("私钥输入流为空");
}
}
public static RSAPrivateKey loadPrivateKeyByStr(String privateKeyStr)
throws Exception {
try {
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] buffer = base64Decoder.decodeBuffer(privateKeyStr);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(buffer);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return (RSAPrivateKey) keyFactory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此算法");
} catch (InvalidKeySpecException e) {
throw new Exception("私钥非法");
} catch (NullPointerException e) {
throw new Exception("私钥数据为空");
}
}
/**
* 公钥加密过程
*
* @param publicKey 公钥
* @param plainTextData 明文数据
* @return
* @throws Exception 加密过程中的异常信息
*/
public static byte[] encrypt(RSAPublicKey publicKey, byte[] plainTextData)
throws Exception {
if (publicKey == null) {
throw new Exception("加密公钥为空, 请设置");
}
Cipher cipher = null;
try {
// 使用默认RSA
cipher = Cipher.getInstance("RSA");
// cipher= Cipher.getInstance("RSA", new BouncyCastleProvider());
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] output = cipher.doFinal(plainTextData);
return output;
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此加密算法");
} catch (NoSuchPaddingException e) {
e.printStackTrace();
return null;
} catch (InvalidKeyException e) {
throw new Exception("加密公钥非法,请检查");
} catch (IllegalBlockSizeException e) {
throw new Exception("明文长度非法");
} catch (BadPaddingException e) {
throw new Exception("明文数据已损坏");
}
}
/**
* 私钥加密过程
*
* @param privateKey 私钥
* @param plainTextData 明文数据
* @return
* @throws Exception 加密过程中的异常信息
*/
public static byte[] encrypt(RSAPrivateKey privateKey, byte[] plainTextData)
throws Exception {
if (privateKey == null) {
throw new Exception("加密私钥为空, 请设置");
}
Cipher cipher = null;
try {
// 使用默认RSA
cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
byte[] output = cipher.doFinal(plainTextData);
return output;
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此加密算法");
} catch (NoSuchPaddingException e) {
e.printStackTrace();
return null;
} catch (InvalidKeyException e) {
throw new Exception("加密私钥非法,请检查");
} catch (IllegalBlockSizeException e) {
throw new Exception("明文长度非法");
} catch (BadPaddingException e) {
throw new Exception("明文数据已损坏");
}
}
/**
* 私钥解密过程
*
* @param privateKey 私钥
* @param cipherData 密文数据
* @return 明文
* @throws Exception 解密过程中的异常信息
*/
public static byte[] decrypt(RSAPrivateKey privateKey, byte[] cipherData)
throws Exception {
if (privateKey == null) {
throw new Exception("解密私钥为空, 请设置");
}
Cipher cipher = null;
try {
// 使用默认RSA
cipher = Cipher.getInstance("RSA");
// cipher= Cipher.getInstance("RSA", new BouncyCastleProvider());
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] output = cipher.doFinal(cipherData);
return output;
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此解密算法");
} catch (NoSuchPaddingException e) {
e.printStackTrace();
return null;
} catch (InvalidKeyException e) {
throw new Exception("解密私钥非法,请检查");
} catch (IllegalBlockSizeException e) {
throw new Exception("密文长度非法");
} catch (BadPaddingException e) {
throw new Exception("密文数据已损坏");
}
}
/**
* 公钥解密过程
*
* @param publicKey 公钥
* @param cipherData 密文数据
* @return 明文
* @throws Exception 解密过程中的异常信息
*/
public static byte[] decrypt(RSAPublicKey publicKey, byte[] cipherData)
throws Exception {
if (publicKey == null) {
throw new Exception("解密公钥为空, 请设置");
}
Cipher cipher = null;
try {
// 使用默认RSA
cipher = Cipher.getInstance("RSA");
// cipher= Cipher.getInstance("RSA", new BouncyCastleProvider());
cipher.init(Cipher.DECRYPT_MODE, publicKey);
byte[] output = cipher.doFinal(cipherData);
return output;
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此解密算法");
} catch (NoSuchPaddingException e) {
e.printStackTrace();
return null;
} catch (InvalidKeyException e) {
throw new Exception("解密公钥非法,请检查");
} catch (IllegalBlockSizeException e) {
throw new Exception("密文长度非法");
} catch (BadPaddingException e) {
throw new Exception("密文数据已损坏");
}
}
/**
* 字节数据转十六进制字符串
*
* @param data 输入数据
* @return 十六进制内容
*/
public static String byteArrayToString(byte[] data) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < data.length; i++) {
// 取出字节的高四位 作为索引得到相应的十六进制标识符 注意无符号右移
stringBuilder.append(HEX_CHAR[(data[i] & 0xf0) >>> 4]);
// 取出字节的低四位 作为索引得到相应的十六进制标识符
stringBuilder.append(HEX_CHAR[(data[i] & 0x0f)]);
if (i < data.length - 1) {
stringBuilder.append(' ');
}
}
return stringBuilder.toString();
}
public static String RSA(String key) throws Exception {
String publicPath = "C:\\Users\\10908"; //公匙存放位置
String privatePath = "C:\\Users\\10908"; //私匙存放位置
Base64 base64 = new Base64();
String signKey = key;
// 公钥加密过程
byte[] cipherData = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile(publicPath)),
signKey.getBytes());
String cipher = new String(base64.encode(cipherData));
// 私钥解密过程
byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile(privatePath)),
base64.decode(cipher));
String restr = new String(res);
// System.out.println("原文:" + signKey);
// System.out.println("加密:" + cipher);
// System.out.println("解密:" + restr);
// System.out.println();
return restr;
}
public static void main(String[] args) throws Exception {
String publicPath = "C:\\Users\\10908"; //公匙存放位置
String privatePath = "C:\\Users\\10908"; //私匙存放位置
Base64 base64 = new Base64();
System.out.println("--------------公钥加密私钥解密过程-------------------");
String signKey = "469468403832192271371540108180328462414842553340";
// 公钥加密过程
byte[] cipherData = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile(publicPath)),
signKey.getBytes());
String cipher = new String(base64.encode(cipherData));
// 私钥解密过程
byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile(privatePath)),
base64.decode(cipher));
String restr = new String(res);
System.out.println("原文:" + signKey);
System.out.println("加密:" + cipher);
System.out.println("解密:" + restr);
System.out.println();
System.out.println("--------------私钥加密公钥解密过程-------------------");
// 私钥加密过程
cipherData = RSAEncrypt.encrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile(privatePath)), signKey.getBytes());
cipher = new String(base64.encode(cipherData));
// 公钥解密过程
res = RSAEncrypt.decrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile(publicPath)), base64.decode(cipher));
restr = new String(res);
System.out.println("原文:" + signKey);
System.out.println("加密:" + cipher);
System.out.println("解密:" + restr);
System.out.println();
}
}
\ No newline at end of file
import java.util.Scanner;
public class SHA1
{
private final int A=0x67452301;
private final int B=0xefcdab89;
private final int C=0x98badcfe;
private final int D=0x10325476;
private final int E=0xc3d2e1f0;
private int Atemp,Btemp,Ctemp,Dtemp,Etemp;
private void init()
{
Atemp = A;
Btemp = B;
Ctemp = C;
Dtemp = D;
Etemp = E;
}
private int shift(int a , int s) //循环左移
{
return (a << s) | (a >>> (32 - s));
}
private int[] add(String str) //字符串转换为int并完成添加
{
int num = ((str.length() + 8) / 64) + 1;
int strByte[] = new int[num*16];
for(int i = 0 ; i < num*16 ; i ++)
{
strByte[i] = 0;
}
int len = str.length() , i;
for(i = 0 ; i < len ; i ++)
{
strByte[i>>2] |= (str.charAt(i) & 0xff )<<(((i^3) % 4)*8); //四个字符一个int,每个字符的8位放到对应位置
}
strByte[i>>2] |= 0x80 << (((i^3) % 4)*8); //最后位加1后补0
strByte[num*16 - 1] = str.length() * 8; //保存长度
return strByte;
}
private void Mainloop(int num[]) //循环加密
{
int w[] = new int[80];
for(int i = 0 ; i < 16 ; i ++) w[i] = num[i];
for(int i = 16 ; i < 80 ; i ++)
{
w[i] = shift(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1);
}
int F , k; //每轮的循环运算顺序有g决定,F是决定abc的
int a = Atemp , b = Btemp , c = Ctemp , d = Dtemp , e = Etemp;
for(int i = 0 ; i < 80 ; i ++) //四轮运算
{
if(i < 20)
{
F = (b & c) | (( ~b ) & d);
k = 0x5a827999;
}
else if(i < 40)
{
F = b ^ c ^ d ;
k = 0x6ed9eba1;
}
else if(i < 60)
{
F = (b & c) | (b & d) | ( c & d);
k = 0x8f1bbcdc;
}
else
{
F = b ^ c ^ d ;
k = 0xca62c1d6;
}
int tmp = shift(a , 5) + e + w[i] + k + F;
e = d ;
d = c ;
c = shift(b , 30) ;
b = a;
a = tmp;
}
Atemp = a + Atemp; //保存当前组结果
Btemp = b + Btemp;
Ctemp = c + Ctemp;
Dtemp = d + Dtemp;
Etemp = e + Etemp;
}
private String changeHex(int a) //转换为字符串
{
String str = "";
for(int i = 0 ; i < 4 ; i ++)
{
str += String.format("%2s" , Integer.toHexString(((a >> (i^3)*8) % (1<<8)) & 0xff)).replace(' ', '0') ;
}
return str;
}
public String Md5(String str)
{
init();
int strByte[] = add(str);
for(int i = 0 ; i < strByte.length / 16 ; i ++)
{
int num[] = new int[16];
for(int j = 0 ; j < 16 ; j ++)
{
num[j] = strByte[i*16+j];
//System.out.println(num[j]);
}
Mainloop(num);
}
return changeHex(Atemp) + changeHex(Btemp) + changeHex(Ctemp) + changeHex(Dtemp) + changeHex(Etemp);
}
private static SHA1 instance;
public static SHA1 getInstance()
{
if(instance == null)
{
instance = new SHA1();
}
return instance;
}
private SHA1(){};
public static void main(String[] args) throws Exception
{
Scanner cin = new Scanner(System.in);
String str = new String();
while(cin.hasNext())
{
str = cin.next();
String str2 = SHA1.getInstance().Md5(str);
System.out.println(str2);
}
//System.out.println(md5(str));
}
}
\ No newline at end of file
package com.hao.digitalsignature.entity;
import com.baomidou.mybatisplus.annotation.*;
@TableName("picture")
public class Files {
@TableId(type = IdType.AUTO)
private Integer picture_id;
private String picture_name;
private String picture_type;
@TableField(insertStrategy = FieldStrategy.IGNORED)
private Integer picture_user;
private String createtime;
private String picture_realname;
private String dig;
public Files(Integer picture_id, String picture_name, String picture_type, Integer picture_user, String createtime, String picture_realname, String dig) {
this.picture_id = picture_id;
this.picture_name = picture_name;
this.picture_type = picture_type;
this.picture_user = picture_user;
this.createtime = createtime;
this.picture_realname = picture_realname;
this.dig = dig;
}
public Integer getPicture_id() {
return picture_id;
}
public void setPicture_id(Integer picture_id) {
this.picture_id = picture_id;
}
public String getPicture_name() {
return picture_name;
}
public void setPicture_name(String picture_name) {
this.picture_name = picture_name;
}
public String getPicture_type() {
return picture_type;
}
public void setPicture_type(String picture_type) {
this.picture_type = picture_type;
}
public Integer getPicture_user() {
return picture_user;
}
public void setPicture_user(Integer picture_user) {
this.picture_user = picture_user;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public String getPicture_realname() {
return picture_realname;
}
public void setPicture_realname(String picture_realname) {
this.picture_realname = picture_realname;
}
public String getDig() {
return dig;
}
public void setDig(String dig) {
this.dig = dig;
}
@Override
public String toString() {
return "Files{" +
"picture_id=" + picture_id +
", picture_name='" + picture_name + '\'' +
", picture_type='" + picture_type + '\'' +
", picture_user=" + picture_user +
", createtime='" + createtime + '\'' +
", picture_realname='" + picture_realname + '\'' +
", dig='" + dig + '\'' +
'}';
}
}
package com.hao.digitalsignature.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.util.List;
public class User {
@TableId(type = IdType.AUTO)
private Integer user_id;
private String user_name;
private String password;
private String realname;
private String email;
private String telephone;
private String country;
@TableField(exist = false)
private List<Files> files;
public User(Integer user_id, String user_name, String password, String realname, String email, String telephone, String country) {
this.user_id = user_id;
this.user_name = user_name;
this.password = password;
this.realname = realname;
this.email = email;
this.telephone = telephone;
this.country = country;
}
public Integer getUser_id() {
return user_id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public List<Files> getFiles() {
return files;
}
public void setFiles(List<Files> files) {
this.files = files;
}
@Override
public String toString() {
return "User{" +
"user_id=" + user_id +
", user_name='" + user_name + '\'' +
", password='" + password + '\'' +
", realname='" + realname + '\'' +
", email='" + email + '\'' +
", telephone='" + telephone + '\'' +
", country='" + country + '\'' +
", files=" + files +
'}';
}
}
package com.hao.digitalsignature.interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("user拦截器");
return true;
}
}
package com.hao.digitalsignature.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hao.digitalsignature.entity.Files;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface FileMapper extends BaseMapper<Files> {
// @Select("select * from picture where picture_user = #{picture_user}")
// List<Files> selectByUid(Integer picture_user);
}
package com.hao.digitalsignature.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hao.digitalsignature.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface UserMapper extends BaseMapper<User> {
// extend BaseMapper 由plus提供,不需要自己写接口
// @Select("select * from user")
// public List<User> getAll();
//
// @Insert("insert into user values(#{user_id},#{user_name},#{password})")
// public int insert(User user);
//
// @Delete("delete from user where id=#{id}")
// int delete(int id);
//
// @Update("update user set username=#{user_name} where id=#{user_id}")
// int update(User user);
//
// @Select("select * from user where id=#{user_id}")
// User find(int id);
@Select("select * from user")
@Results(
{ //前面是表里字段,后面是类里的字段
@Result(column = "id",property = "id"),
@Result(column = "username",property = "username"),
@Result(column = "id",property = "files",javaType = List.class,
many = @Many(select = "com.hao.digitalsignature.mapper.FileMapper.selectByUid")
)
}
)
List<User> selectAllUserAndFiles();
}
spring.devtools.restart.enabled=true
spring.devtools.restart.additional-paths=src/main/java
server.port=8080
#ϴļС
logging.logback.rollingpolicy.max-file-size=10MB
#swagger
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/shuziqianming?useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=root
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#spring.mvc.static-path-pattern=/static/**
\ No newline at end of file
* {
padding: 0;
margin: 0;
}
.el-header,
.el-footer {
background-color: #B3C0D1;
color: #333;
text-align: center;
line-height: 60px;
font-size: 20px;
font-weight: bold;
}
.el-aside {
background-color: #545c64;
color: #333;
text-align: center;
height: 800px;
}
.el-main {
color: #333;
text-align: center;
height: 800px;
}
body>.el-container {
margin-bottom: 40px;
}
.el-col {
background-color: #545c64;
color: white;
overflow: hidden;
}
.el-col h4 {
height: 56px;
line-height: 56px;
width: 192px;
}
.el-main {
text-align: start;
}
.el-menu {
width: 200px;
}
.el-breadcrumb {
margin-bottom: 20px;
}
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409EFF;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
.el-icon--right {}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 1. 引入vue -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 2. 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 3. 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<link rel="stylesheet" href="./css/index.css">
<link rel="stylesheet" href="./css/upload.css">
<title>Document</title>
<style>
</style>
</head>
<body>
<div id="app">
<el-container>
<el-header>
数字图像保护系统
</el-header>
<el-container>
<el-aside width="200px">
<el-col :span="24">
<h4>首页</h4>
<el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen"
@close="handleClose" background-color="#545c64" text-color="#fff"
active-text-color="#ffd04b">
<el-submenu index="1">
<template slot="title">
<i class="sel-icon-picture"></i>
<span>图片版权管理</span>
</template>
<el-menu-item-group>
<el-menu-item index="1-1">图片管理</el-menu-item>
<el-menu-item index="1-2">上传图片</el-menu-item>
</el-menu-item-group>
</el-submenu>
<el-submenu index="2">
<template slot="title">
<i class="el-icon-menu"></i>
<span>系统管理</span>
</template>
<el-menu-item-group>
<el-menu-item index="2-1">用户管理</el-menu-item>
<el-menu-item index="2-2">注册</el-menu-item>
<el-menu-item index="2-3">菜单管理</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu-item>
</el-menu>
</el-col>
</el-row>
</el-aside>
<el-main>
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
<el-breadcrumb-item>图片管理</el-breadcrumb-item>
</el-breadcrumb>
<el-button size="small" type="primary" @click="handleCreate()">点击上传</el-button>
<div id="addpic">
<el-dialog title="添加图片" :visible.sync="dialogFormVisible">
<el-form :model="formData" label-width="80px" :rules="rules" ref="forms">
<el-form-item label="图片名称" :rules="rules.picture_name" prop="picture_name">
<el-input v-model="formData.picture_name" ></el-input>
</el-form-item>
<el-form-item label="图片" :rules="rules.picture" prop="picture">
<el-upload
action="#"
list-type="picture-card"
:auto-upload="false"
:limit="1"
:on-change="handlePicturePreview"
:on-remove="handleRemove"
:on-success="handlePicturePreview"
ref="mYupload"
:http-request="uploadFile"
>
<i slot="default" class="el-icon-plus"></i>
<div slot="file" slot-scope="{file}">
<img
class="el-upload-list__item-thumbnail"
:src="file.url" alt=""
>
<span class="el-upload-list__item-actions">
<span
class="el-upload-list__item-preview"
@click="handlePictureCardPreview(file)"
>
<i class="el-icon-zoom-in"></i>
</span>
<span
v-if="!disabled"
class="el-upload-list__item-delete"
@click="clearFiles()"
>
<i class="el-icon-delete"></i>
</span>
</span>
</div>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleEdit()">立即创建</el-button>
<el-button @click="dialogFormVisible = false,resetForm()">取消</el-button>
</el-form-item>
</el-form>.
</el-dialog>
</div>
<el-table :data="filelist" stripe style="width: 100%" :model="formData">
<el-table-column prop="picture_name" label="名称" width="180">
</el-table-column>
<el-table-column prop="picture_realname" label="真实名称" width="180">
</el-table-column>
<el-table-column prop="picture_type" label="类型" width="180">
</el-table-column>
<el-table-column prop="picture_user" label="用户" width="180">
</el-table-column>
<el-table-column label="图片" align="center">
<templmate slot-scope="scope">
<img :src="'./img/'+scope.row.picture_realname+'.'+scope.row.picture_type" width="100px"/>
</templmate>
</el-table-column>
<el-table-column prop="createtime" label="创建时间">
</el-table-column>
<el-table-column label="功能">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="handleDownload(scope.row)">下载</el-button>
</template>
</el-table-column>
</el-table>
</el-main>
</el-container>
</el-container>
</div>
</body>
<script src="./js/axios-0.27.2.js"></script>
<script type="text/javascript" src="./js/jquery-3.6.0.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
par:'',
filelist: [],
formData: {},
dialogFormVisible:false,
dialogFormVisible4Edit: false,
dialogImageUrl:'',
dialogVisible:false,
disabled:false,
rules: {
picture_name: [{ required: true, message: '请输入图片名称', trigger: 'blur' }],
picture:[{ required: true, message: '请上传图片', trigger: 'blur' }]
},
}
},
methods: {
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
},
handlePicturePreview(file) {
console.log(file)
this.par=file.raw;
},
handlePreview(file) {
console.log(file);
},
handleRemove(file) {
console.log(file)
},
clearFiles () {
this.$refs['mYupload'].clearFiles();
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
this.dialogVisible = true;
},
handleDownload(file) {
let f =file.picture_realname+"."+file.picture_type
axios.post("/file/download",f,).then((result)=>{
var url = (window.document.location.href+"img/"+result.config.data)
var that = this
var fileName = file.picture_name
this.convertUrlToBase64(url).then(function (base64) {
var blob = that.convertBase64UrlToBlob(base64); // 转为blob对象
// 下载
if (that.myBrowser() == "IE") {
window.navigator.msSaveBlob(blob, fileName + ".png");
} else if (that.myBrowser() == "FF") {
window.location.href = url;
} else {
var a = document.createElement("a");
a.download = fileName;
a.href = URL.createObjectURL(blob);
document.body.appendChild(a)
a.click();
URL.revokeObjectURL(a.href) // 释放URL 对象
document.body.removeChild(a)
}
});
})
},
// 转换为base64
convertUrlToBase64(url) {
return new Promise(function (resolve, reject) {
var img = new Image();
//设置图片跨越,没有跨越cavas会被污染无法画出
img.crossOrigin = "Anonymous";
img.src = url;
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var ext = img.src
.substring(img.src.lastIndexOf(".") + 1)
.toLowerCase();
//转换为base64
var dataURL = canvas.toDataURL("image/" + ext);
var base64 = {
dataURL: dataURL,
type: "image/" + ext,
ext: ext
};
resolve(base64);
};
});
},
// base64转换为blob流
convertBase64UrlToBlob(base64) {
var parts = base64.dataURL.split(";base64,");
var contentType = parts[0].split(":")[1];
var raw = window.atob(parts[1]);
var rawLength = raw.length;
var uInt8Array = new Uint8Array(rawLength);
for (var i = 0; i < rawLength; i++) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {
type: contentType
});
},
// 判断浏览器
myBrowser() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
if (userAgent.indexOf("OPR") > -1) {
return "Opera";
} //判断是否Opera浏览器 OPR/43.0.2442.991
if (userAgent.indexOf("Firefox") > -1) {
return "FF";
} //判断是否Firefox浏览器 Firefox/51.0
if (userAgent.indexOf("Trident") > -1) {
return "IE";
} //判断是否IE浏览器 Trident/7.0; rv:11.0
if (userAgent.indexOf("Edge") > -1) {
return "Edge";
} //判断是否Edge浏览器 Edge/14.14393
if (userAgent.indexOf("Chrome") > -1) {
return "Chrome";
} // Chrome/56.0.2924.87
if (userAgent.indexOf("Safari") > -1) {
return "Safari";
} //判断是否Safari浏览器 AppleWebKit/534.57.2 Version/5.1.7 Safari/534.57.2
},
init(){
axios.get("/file/findAll", this.formData, ).then((result) => {
this.filelist = result.data
})
},
uploadFile(params) {
console.log("uploadFile", params);
const _file = params.file;
// 通过 FormData 对象上传文件
var formData = new FormData();
formData.append("file", _file);
axios.post("/file/upload",formData).then((res)=>{
console.log(res.data)
this.formData.picture_realname=res.data.split(".")[0]
console.log(this.picture_realname)
this.formData.picture_type=res.data.split(".")[1]
})
},
//重置表单
resetForm() {
this.formData = {};
//this.$refs['form'].clearValidate();
this.$nextTick(() => {
this.$refs.forms.clearValidate()
})
},
//弹出添加窗口
handleCreate() {
this.resetForm();
this.dialogFormVisible = true;
},
handleEdit() {
const _file = this.par;
// 通过 FormData 对象上传文件
var formData = new FormData();
formData.append("file", _file);
axios.post("/file/upload",formData).then((res)=>{
console.log(res.data)
this.formData.picture_realname=res.data.split(".")[0]
console.log(this.picture_realname)
this.formData.picture_type=res.data.split(".")[1]
console.log(this.formData.picture_type)
axios.post("/file/save", this.formData).then((result) => {
console.log(result)
console.log(this.formData )
this.resetForm();
this.dialogFormVisible = false;
this.clearFiles()
});
}).then(function (){
this.init()
})
},
},
mounted() {
this.init();
}
})
</script>
</html>
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
package com.hao.digitalsignature;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DigitalsignatureApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册