---
title: "BouncyCastleProvider加密的时候千万别乱new BouncyCastleProvider 切记"
author: "lyjilu"
date: "2015-07-21T14:47:42Z"
tags: []
categories: ["编程语言"]
slug: "bouncycastleprovider-new-bouncycastleprovider"
draft: false
lastmod: "2015-07-21T14:47:42Z"
id: 2229059
url: "https://lyjilu.iteye.com/blog/2229059"
---

BouncyCastleProvider加密的时候千万别乱new BouncyCastleProvider 切记

应该用：

static{

if (Security.getProvider(BouncyCastleProvider.PROVIDER\_NAME) == null){

System.out.println("security provider BC not found");

Security.addProvider(new BouncyCastleProvider());

}

}

 

Cipher cipher = Cipher.getInstance(ALGORITHM\_PADDING,"BC");

下面这种方式有问题：

Cipher cipher = Cipher.getInstance(ALGORITHM\_PADDING,new BouncyCastleProvider());