| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.kuali.rice.ksb.messaging; |
| 18 |
|
|
| 19 |
|
import org.junit.Test; |
| 20 |
|
import org.kuali.rice.core.api.config.property.Config; |
| 21 |
|
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 22 |
|
import org.kuali.rice.ksb.test.KSBTestCase; |
| 23 |
|
|
| 24 |
|
import java.io.FileInputStream; |
| 25 |
|
import java.security.KeyStore; |
| 26 |
|
import java.security.PrivateKey; |
| 27 |
|
import java.security.PublicKey; |
| 28 |
|
import java.security.Signature; |
| 29 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 1 |
Complexity Density: 0.06 |
|
| 30 |
|
public class DigitalSignatureTest extends KSBTestCase { |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@throws |
| 37 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
4
-
|
|
| 38 |
0
|
@Test public void testSigning() throws Exception {... |
| 39 |
|
|
| 40 |
0
|
Config config = ConfigContext.getCurrentContextConfig(); |
| 41 |
|
|
| 42 |
|
|
| 43 |
0
|
Signature rsa = Signature.getInstance("SHA1withRSA"); |
| 44 |
0
|
String keystoreLocation = config.getKeystoreFile(); |
| 45 |
0
|
String keystoreAlias = config.getKeystoreAlias(); |
| 46 |
0
|
String keystorePassword = config.getKeystorePassword(); |
| 47 |
0
|
KeyStore keystore = KeyStore.getInstance("JKS"); |
| 48 |
0
|
keystore.load(new FileInputStream(keystoreLocation), keystorePassword.toCharArray()); |
| 49 |
0
|
PrivateKey privateKey = (PrivateKey)keystore.getKey(keystoreAlias, keystorePassword.toCharArray()); |
| 50 |
|
|
| 51 |
0
|
rsa.initSign(privateKey); |
| 52 |
|
|
| 53 |
0
|
String imLovinIt = "Ba-da-ba-ba-baa, I'm lovin' it!"; |
| 54 |
0
|
rsa.update(imLovinIt.getBytes()); |
| 55 |
|
|
| 56 |
0
|
byte[] sigToVerify = rsa.sign(); |
| 57 |
|
|
| 58 |
|
|
| 59 |
0
|
PublicKey publicKey = keystore.getCertificate(keystoreAlias).getPublicKey(); |
| 60 |
0
|
Signature verifySig = Signature.getInstance("SHA1withRSA"); |
| 61 |
0
|
verifySig.initVerify(publicKey); |
| 62 |
0
|
verifySig.update(imLovinIt.getBytes()); |
| 63 |
0
|
boolean verifies = verifySig.verify(sigToVerify); |
| 64 |
0
|
System.out.println("signature verifies: " + verifies); |
| 65 |
|
|
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
} |