Skip to content

Instantly share code, notes, and snippets.

View Coffee0127's full-sized avatar

Bo-Xuan Fan Coffee0127

View GitHub Profile
@Coffee0127
Coffee0127 / banner.txt
Last active December 9, 2022 03:46
Pokemon
_____ ___ ___ _ _ _
o O O |_ _| | _ \ / \ | \| | ___ / |
o | | | / | - | | .' | / _ \ _ | |
TS__[O] _|_|_ |_|_\ |_|_| |_|\_| \___/ _(_)_ _|_|_
{======| _|"""""| _|"""""| _|"""""| _|"""""| _|"""""| _|"""""| _|"""""| _|"""""|
./o--000' "'-0-0-' "'-0-0-' "'-0-0-' "'-0-0-' "'-0-0-' "'-0-0-' "'-0-0-' "'-0-0-'
${AnsiColor.GREEN}:: Spring Boot ::${Ansi.DEFAULT} ${spring-boot.formatted-version}
@Coffee0127
Coffee0127 / Demo.java
Created January 15, 2021 06:33
Java sign / verify with RSA key pair
public class Demo {
public static void main(String[] args) throws Exception {
String plainText = "Hello World";
String signature = sign(plainText, readPrivateKey(new File("/Users/bfan01/Desktop/private_key.pem")));
System.out.println(signature);
System.out.println(verify(plainText, signature, readPublicKey(new File("/Users/bfan01/Desktop/public.pem"))));
}
public static String sign(String plainText, PrivateKey privateKey) throws Exception {
Signature privateSignature = Signature.getInstance("SHA256withRSA");