public OpenPgpV4Fingerprint restoreSecretKeyServerBackup ( AskForBackupCodeCallback codeCallback ) throws InterruptedException , PubSubException . NotALeafNodeException , XMPPException . XMPPErrorException , SmackException . NotConnectedException , SmackException . NoResponseException , InvalidBackupCodeException , SmackException . NotLoggedInException , IOException , MissingUserIdOnKeyException , NoBackupFoundException , PGPException { throwIfNoProviderSet ( ) ; throwIfNotAuthenticated ( ) ; SecretkeyElement backup = OpenPgpPubSubUtil . fetchSecretKey ( pepManager ) ; if ( backup == null ) { throw new NoBackupFoundException ( ) ; } String backupCode = codeCallback . askForBackupCode ( ) ; PGPSecretKeyRing secretKeys = SecretKeyBackupHelper . restoreSecretKeyBackup ( backup , backupCode ) ; provider . getStore ( ) . importSecretKey ( getJidOrThrow ( ) , secretKeys ) ; provider . getStore ( ) . importPublicKey ( getJidOrThrow ( ) , BCUtil . publicKeyRingFromSecretKeyRing ( secretKeys ) ) ; ByteArrayOutputStream buffer = new ByteArrayOutputStream ( 2048 ) ; for ( PGPSecretKey sk : secretKeys ) { PGPPublicKey pk = sk . getPublicKey ( ) ; if ( pk != null ) pk . encode ( buffer ) ; } PGPPublicKeyRing publicKeys = new PGPPublicKeyRing ( buffer . toByteArray ( ) , new BcKeyFingerprintCalculator ( ) ) ; provider . getStore ( ) . importPublicKey ( getJidOrThrow ( ) , publicKeys ) ; return new OpenPgpV4Fingerprint ( secretKeys ) ; }
Fetch a secret key backup from the server and try to restore a selected secret key from it .