1 package net.sumaris.core.service.crypto; 2 3 /* 4 * #%L 5 * Duniter4j :: Core API 6 * %% 7 * Copyright (C) 2014 - 2015 EIS 8 * %% 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as 11 * published by the Free Software Foundation, either version 3 of the 12 * License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public 20 * License along with this program. If not, see 21 * <http://www.gnu.org/licenses/gpl-3.0.html>. 22 * #L% 23 */ 24 25 26 import net.sumaris.core.util.crypto.KeyPair; 27 28 /** 29 * Crypto services (sign...) 30 * Created by eis on 10/01/15. 31 */ 32 public interface CryptoService { 33 34 /** 35 * generate a crypto seed, using default N,r,p parameters (4096,16,1) 36 * @param salt 37 * @param password 38 * @return 39 */ 40 byte[] getSeed(String salt, String password); 41 42 byte[] getSeed(String salt, String password, int N, int r, int p); 43 44 /** 45 * Returns a new signing key pair generated from salt and password. 46 * The salt and password must contain enough entropy to be secure. 47 * 48 * @param salt 49 * @param password 50 * @return 51 */ 52 KeyPair getKeyPair(String salt, String password); 53 54 /** 55 * Returns a new signing key pair generated from salt and password. 56 * The salt and password must contain enough entropy to be secure. 57 * 58 * @param seed 59 * @return 60 */ 61 KeyPair getKeyPairFromSeed(byte[] seed); 62 63 KeyPair getRandomKeypair(); 64 65 String sign(String message, byte[] secretKey); 66 67 String sign(String message, String secretKey); 68 69 String box(String message, byte[] nonce, String senderSignSk, String receiverSignPk); 70 71 String box(String message, byte[] nonce, byte[] senderSignSk, byte[] receiverSignPk); 72 73 byte[] getBoxRandomNonce(); 74 75 String openBox(String cypherText, String nonce, String senderSignPk, String receiverSignSk); 76 77 String openBox(String cypherText, byte[] nonce, byte[] senderSignPk, byte[] receiverSignSk); 78 79 boolean verify(String message, String signature, String publicKey); 80 81 /** 82 * Do a SHA256 then a hexa convert 83 * @param message 84 * @return 85 */ 86 String hash(String message); 87 }