-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Took 13 hours 14 minutes
- Loading branch information
Showing
18 changed files
with
488 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.py7hon; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
/** | ||
* 启动类 | ||
* | ||
* @author Seven | ||
* @version 1.0 | ||
* @date 2020/9/19 22:52 | ||
*/ | ||
@SpringBootApplication | ||
@Controller | ||
public class ThresholdSchemeApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ThresholdSchemeApplication.class, args); | ||
} | ||
|
||
@RequestMapping({"/", "/home", "/index"}) | ||
public String home() { | ||
return "index"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.py7hon.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
/** | ||
* 安全配置 | ||
* | ||
* @author Seven | ||
* @version 1.0 | ||
* @date 2020/9/13 22:57 | ||
*/ | ||
@Configuration | ||
public class SecurityConfig implements WebMvcConfigurer { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
// .allowedOrigins("http://127.0.0.1:5500", "https://127.0.0.1:*") | ||
.allowedOrigins("*") | ||
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") | ||
.allowCredentials(true) | ||
.maxAge(3600) | ||
.allowedHeaders("*"); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/com/py7hon/controller/ThresholdSchemeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.py7hon.controller; | ||
|
||
import com.py7hon.entity.Piece; | ||
import com.py7hon.threshold.scheme.ThresholdScheme; | ||
import com.py7hon.threshold.scheme.chinese.remainder.theorem.ChineseRemainderTheorem; | ||
import com.py7hon.threshold.scheme.shamir.Shamir; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 门限方案接口 | ||
* | ||
* @author Seven | ||
* @version 1.0 | ||
* @date 2020/9/19 23:10 | ||
*/ | ||
@RestController | ||
public class ThresholdSchemeController { | ||
|
||
@GetMapping("/api/generate-piece/{type}") | ||
public ResponseEntity<?> genPiece( | ||
@PathVariable("type") String type, | ||
@RequestParam("secretKey") long secretKey, | ||
@RequestParam("totalPieceNumber") int totalPieceNumber, | ||
@RequestParam("minEffectivePieceNumber") int minEffectivePieceNumber, | ||
@RequestParam("mod") long mod | ||
) { | ||
ThresholdScheme thresholdScheme = getThresholdScheme(type); | ||
|
||
if (thresholdScheme == null) { | ||
return ResponseEntity.badRequest().build(); | ||
} | ||
|
||
Piece[] pieces = thresholdScheme.genPieces(secretKey, totalPieceNumber, minEffectivePieceNumber, mod); | ||
return ResponseEntity.ok(pieces); | ||
} | ||
|
||
@RequestMapping("/api/restore-secret-key/{type}") | ||
public ResponseEntity<?> restoreSecretKey( | ||
@PathVariable("type") String type, | ||
@RequestParam("mod") long mod, | ||
@RequestBody List<Piece> pieces | ||
) { | ||
ThresholdScheme thresholdScheme = getThresholdScheme(type); | ||
|
||
if (thresholdScheme == null) { | ||
return ResponseEntity.badRequest().build(); | ||
} | ||
|
||
long secretKey = thresholdScheme.restoreSecretKey(pieces.toArray(new Piece[0]), 1, 1, mod); | ||
return ResponseEntity.ok(secretKey); | ||
} | ||
|
||
/** | ||
* 根据类别获取门限方案 | ||
* | ||
* @param type 类别。shamir 或 chinese-remainder | ||
* @return 门限方案 | ||
*/ | ||
private ThresholdScheme getThresholdScheme(String type) { | ||
if (type == null) { | ||
return null; | ||
} | ||
|
||
switch (type) { | ||
case "shamir": | ||
return new Shamir(); | ||
case "chinese-remainder": | ||
return new ChineseRemainderTheorem(); | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.py7hon.entity; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* 块。将密钥按照某种规则分解成的密码片。对应于多项式的坐标,index表示横坐标,value表示纵坐标 | ||
* | ||
* @author Seven | ||
* @version 1.0 | ||
* @date 2020-09-14 22:18 | ||
*/ | ||
@Data | ||
public class Piece { | ||
/** | ||
* 块下标,从 1 开始 | ||
*/ | ||
private int index; | ||
|
||
/** | ||
* 块存储的数值 | ||
*/ | ||
private long value; | ||
|
||
public Piece() { | ||
} | ||
|
||
/** | ||
* 构造器 | ||
* | ||
* @param index 块下标 | ||
* @param value 块存储的数值 | ||
*/ | ||
public Piece(int index, long value) { | ||
this.index = index; | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: | ||
port: 8089 |
Oops, something went wrong.