Example usage for java.security.interfaces RSAPrivateKey getFormat

List of usage examples for java.security.interfaces RSAPrivateKey getFormat

Introduction

In this page you can find the example usage for java.security.interfaces RSAPrivateKey getFormat.

Prototype

public String getFormat();

Source Link

Document

Returns the name of the primary encoding format of this key, or null if this key does not support encoding.

Usage

From source file:com.kuzumeji.platform.standard.SecurityServiceTest.java

@Test
public void testKeyPair() {
    // RSA???//w  w w . j a  v  a2s . c om
    final KeyPair keyPair = testee.generateKeyPair();
    final RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
    final RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
    LOG.debug("?->{}", dumpKeyPair(publicKey));
    LOG.debug("?->{}", dumpKeyPair(privateKey));
    // RSA???/
    testee.saveKeyPair("testee", keyPair);
    final KeyPair keyPair2 = testee.loadKeyPair("testee");
    assertThat(keyPair2.getPublic().getAlgorithm(), is(publicKey.getAlgorithm()));
    assertThat(keyPair2.getPublic().getFormat(), is(publicKey.getFormat()));
    assertThat(keyPair2.getPublic().getEncoded(), is(publicKey.getEncoded()));
    assertThat(keyPair2.getPrivate().getAlgorithm(), is(privateKey.getAlgorithm()));
    assertThat(keyPair2.getPrivate().getFormat(), is(privateKey.getFormat()));
    assertThat(keyPair2.getPrivate().getEncoded(), is(privateKey.getEncoded()));
    // ???(??)
    final File file = testee.savePublicKeyFile(publicKey);
    LOG.debug("? : {}", file.getPath());
}