00001 00010 #include "PKIFXSECCryptoKeyRaw.h" 00012 struct PKIFXSECCryptoKeyRawImpl 00013 { 00014 00015 PKIFXSECCryptoKeyRawImpl(); 00016 CPKIFKeyMaterialPtr m_km; 00017 00018 static bool s_bInitialized; 00019 static XMLCh * s_provName; 00020 }; 00021 00022 bool PKIFXSECCryptoKeyRawImpl::s_bInitialized = false; 00023 XMLCh * PKIFXSECCryptoKeyRawImpl::s_provName = 0; 00031 PKIFXSECCryptoKeyRawImpl::PKIFXSECCryptoKeyRawImpl() 00032 { 00033 if(!s_bInitialized) { 00034 s_bInitialized = true; 00035 s_provName = XMLString::transcode("PKIF XML Security Crypto provider"); 00036 } 00037 } 00039 00046 PKIFXSECCryptoKeyRaw::PKIFXSECCryptoKeyRaw() 00047 :m_impl(new PKIFXSECCryptoKeyRawImpl()) 00048 { 00049 } 00050 00058 PKIFXSECCryptoKeyRaw::PKIFXSECCryptoKeyRaw( 00060 CPKIFKeyMaterialPtr & km 00061 ) 00062 :m_impl(new PKIFXSECCryptoKeyRawImpl()) 00063 { 00064 m_impl->m_km = km; 00065 } 00066 00074 PKIFXSECCryptoKeyRaw::~PKIFXSECCryptoKeyRaw() 00075 { 00076 if(m_impl){ 00077 delete m_impl; 00078 m_impl = 0; 00079 } 00080 } 00081 00089 void PKIFXSECCryptoKeyRaw::setKey( 00091 const unsigned char * inBuf, 00093 unsigned int inLength) 00094 { 00095 CPKIFKeyMaterialPtr km(new CPKIFKeyMaterial()); 00096 km->SetSymmetricKey(inBuf,inLength); 00097 m_impl->m_km = km; 00098 } 00099 00107 unsigned int PKIFXSECCryptoKeyRaw::getKey( 00109 safeBuffer &outBuf) 00110 { 00111 if(!m_impl->m_km) return 0; 00112 int len = m_impl->m_km->GetSymmetricKeyLength(); 00113 if(!len) return len; 00114 outBuf.sbMemcpyIn(m_impl->m_km->GetSymmetricKey(),len); 00115 return len; 00116 } 00117 00125 CPKIFKeyMaterialPtr PKIFXSECCryptoKeyRaw::getPKIFKeyMaterial() 00126 { 00127 return m_impl->m_km; 00128 } 00136 void PKIFXSECCryptoKeyRaw::setPKIFKeyMaterial( 00138 CPKIFKeyMaterialPtr & km) 00139 { 00140 m_impl->m_km = km; 00141 } 00142 00150 const XMLCh * PKIFXSECCryptoKeyRaw::getProviderName() 00151 { 00152 return m_impl->s_provName; 00153 } 00154