Code example for PrivateKey

Methods: getEncoded

0
 
            cipher.init(Cipher.DECRYPT_MODE, keyFact.generateSecret(pbeSpec), pInfo.getAlgParameters());
 
            PKCS8EncodedKeySpec keySpec = pInfo.getKeySpec(cipher);
 
            if (!MessageDigest.isEqual(priKey.getEncoded(), keySpec.getEncoded()))
            { 
                return new SimpleTestResult(false, "Private key does not match"); 
            } 
 
            // 
            // using Cipher parameters test 
            // 
            pbeSpec = new PBEKeySpec(password1);
            keyFact = SecretKeyFactory.getInstance(alg, "BC");
            cipher = Cipher.getInstance(alg, "BC");
 
            cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), params);
 
            wrappedKey = cipher.wrap(priKey);
 
            // 
            // create encrypted object 
            // 
 
            pInfo = new EncryptedPrivateKeyInfo(cipher.getParameters(), wrappedKey);
 
            // 
            // decryption step 
            // 
            pbeSpec = new PBEKeySpec(password2);
 
            cipher = Cipher.getInstance(pInfo.getAlgName(), "BC");
 
            cipher.init(Cipher.DECRYPT_MODE, keyFact.generateSecret(pbeSpec), pInfo.getAlgParameters());
 
            keySpec = pInfo.getKeySpec(cipher);
 
            if (!MessageDigest.isEqual(priKey.getEncoded(), keySpec.getEncoded()))
            { 
                return new SimpleTestResult(false, "Private key does not match"); 
            } 
             
            return new SimpleTestResult(true, getName() + ": Okay"); 
Experience pair programming with AI  Get Codota for Java