Skip to content

Commit a9e2ee5

Browse files
committed
init ut for md5 fingerprint
1 parent 80cf84a commit a9e2ee5

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

core/src/main/java/com/flowci/core/common/helper/CipherHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import java.util.Base64;
3939
import javax.crypto.Cipher;
4040
import javax.crypto.spec.SecretKeySpec;
41+
42+
import org.apache.commons.lang.NotImplementedException;
4143
import sun.security.util.DerInputStream;
4244
import sun.security.util.DerValue;
4345

@@ -100,6 +102,10 @@ public static String decrypt(String encrypted, String privateKey) {
100102
}
101103
}
102104

105+
public static String fingerprintMd5(String publicKey) {
106+
throw new NotImplementedException();
107+
}
108+
103109
private static PrivateKey toPrivateKey(String key)
104110
throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
105111
KeyFactory keyFactory = KeyFactory.getInstance("RSA");

core/src/test/java/com/flowci/core/test/common/CipherHelperTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
import com.flowci.core.common.helper.CipherHelper;
2121
import com.flowci.core.common.helper.CipherHelper.RSA;
2222
import com.flowci.domain.SimpleKeyPair;
23+
import com.flowci.util.StringHelper;
2324
import com.google.common.base.Strings;
2425
import org.junit.Assert;
2526
import org.junit.Test;
2627

28+
import java.io.IOException;
29+
import java.io.InputStream;
30+
31+
import static com.flowci.core.common.helper.CipherHelper.RSA.fingerprintMd5;
32+
2733
public class CipherHelperTest {
2834

2935
private final String source = "!@#!@#!@1fsd";
@@ -53,4 +59,11 @@ public void should_encrypt_decrypt_by_rsa() {
5359

5460
Assert.assertEquals(source, decrypted);
5561
}
62+
63+
@Test
64+
public void should_create_public_key_fingerprint() throws IOException {
65+
InputStream in = CipherHelper.class.getClassLoader().getResourceAsStream("pk_fingerprint");
66+
String publicKey = StringHelper.toString(in);
67+
Assert.assertEquals("09:e6:ce:d3:ba:a3:ee:75:9e:96:7b:55:12:85:c6:4e", fingerprintMd5(publicKey));
68+
}
5669
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCl7ATm/Rsk5jj8oQA3wxxqJFyeYHkcRHxzt+cNnfquwRugnnB0Hh8JBMACeG+es/14jI9tErh4oKGzTiEcCTnBe05C3MVNTbvtO6lP6rM4E+bSJwip2jNKYP7Ozofim2xgD55tGDdWQtBdDOiQWGQAvx+JDLPLGlWYoi1CBnC2zzVHtJCq9+eVhHvghDIjuO1+9iJUwkmh+38ABK2wMxugx46qaNHJuF1p/ncQCB9vb5c6mq3lZQH1usujMGWOH0jctoJVzXX8cJapROWPKombl0svO8+GKAG4FuLcrx+W7OSKCweKPgpnCloCp5Up/zzZeheG8gIYpQPiIvEEKLTb [email protected]

0 commit comments

Comments
 (0)