-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
5 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
58 changes: 58 additions & 0 deletions
58
modules/cryptoservice/src/main/java/org/jpos/q2/cli/crypto/REKEY.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,58 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2021 jPOS Software SRL | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.q2.cli.crypto; | ||
|
||
import java.util.Base64; | ||
import java.util.UUID; | ||
|
||
import org.jpos.crypto.CryptoService; | ||
import org.jpos.crypto.SecureData; | ||
import org.jpos.q2.CLICommand; | ||
import org.jpos.q2.CLIContext; | ||
import org.jpos.util.NameRegistrar; | ||
|
||
@SuppressWarnings("unused") | ||
public class REKEY implements CLICommand { | ||
private CryptoService cs; | ||
|
||
@Override | ||
public void exec(CLIContext cli, String[] args) throws Exception { | ||
cs = NameRegistrar.get("crypto-service", 5000L); | ||
if (args.length < 2) { | ||
usage(cli); | ||
return; | ||
} | ||
if (cs == null) { | ||
cli.println("'crypto-service' not registered"); | ||
return; | ||
} | ||
for (int i=1; i<args.length; i++) { | ||
cs.rekey(UUID.fromString(args[i])); | ||
} | ||
} | ||
|
||
private void usage (CLIContext cli) { | ||
cli.println ("Usage: REKEY uuid(s)"); | ||
} | ||
|
||
private void encrypt (CLIContext cli, String clear) throws Exception { | ||
SecureData sd = cs.aesEncrypt(clear.getBytes()); | ||
cli.println (sd.getId() + " " + Base64.getEncoder().encodeToString(sd.getEncoded())); | ||
} | ||
} |