Module: Ccrypto::Java::DataConversion
- Included in:
- ASN1Engine, CipherEngine, ComparatorUtil, Compression, DataConversionEngine, Decompression, DigestEngine, ECCEngine, ECCKeyBundle, ECCPublicKey, HKDFEngine, HMACEngine, ManagedMemoryBuffer, PBKDF2Engine, PKCS12, PKCS12::ClassMethods, PKCS7Engine, RSAEngine, ScryptEngine, SecretSharingEngine, SecureRandomEngine, SecretKey
- Defined in:
- lib/ccrypto/java/data_conversion.rb
Class Method Summary collapse
-
.included(klass) ⇒ Object
Add the methods to class level.
Instance Method Summary collapse
- #from_b64(str) ⇒ Object
-
#from_hex(str) ⇒ Object
end to_hex.
-
#to_b64(bin) ⇒ Object
end from_hex.
-
#to_b64_mime(bin) ⇒ Object
end to_b64.
- #to_bin(str) ⇒ Object
- #to_hex(bin) ⇒ Object
- #to_java_bytes(val, encoding = nil) ⇒ Object
-
#to_str(bin) ⇒ Object
end from_b64.
Class Method Details
.included(klass) ⇒ Object
Add the methods to class level
72 73 74 75 76 |
# File 'lib/ccrypto/java/data_conversion.rb', line 72 def self.included(klass) klass.class_eval " extend Ccrypto::Java::DataConversion\n END\nend\n" |
Instance Method Details
#from_b64(str) ⇒ Object
27 28 29 |
# File 'lib/ccrypto/java/data_conversion.rb', line 27 def from_b64(str) java.util.Base64.decoder.decode(str) end |
#from_hex(str) ⇒ Object
end to_hex
12 13 14 |
# File 'lib/ccrypto/java/data_conversion.rb', line 12 def from_hex(str) org.bouncycastle.util.encoders.Hex.decode(str) end |
#to_b64(bin) ⇒ Object
end from_hex
17 18 19 |
# File 'lib/ccrypto/java/data_conversion.rb', line 17 def to_b64(bin) String.from_java_bytes(java.util.Base64.encoder.encode(bin)) end |
#to_b64_mime(bin) ⇒ Object
end to_b64
23 24 25 |
# File 'lib/ccrypto/java/data_conversion.rb', line 23 def to_b64_mime(bin) String.from_java_bytes(java.util.Base64.mime_encoder.encode(bin)) end |
#to_bin(str) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/ccrypto/java/data_conversion.rb', line 40 def to_bin(str) if str.nil? ::Java::byte[0].new else str.to_java.getBytes end end |
#to_hex(bin) ⇒ Object
7 8 9 |
# File 'lib/ccrypto/java/data_conversion.rb', line 7 def to_hex(bin) String.from_java_bytes(org.bouncycastle.util.encoders.Hex.encode(to_java_bytes(bin))) end |
#to_java_bytes(val, encoding = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ccrypto/java/data_conversion.rb', line 48 def to_java_bytes(val, encoding = nil) case val when String val.to_java_bytes when java.lang.String if not_empty?(encoding) val.getBytes(encoding) else val.getBytes end when Ccrypto::Java::ManagedMemoryBuffer val.bytes else if val.respond_to?(:encoded) val.encoded else val end end end |
#to_str(bin) ⇒ Object
end from_b64
32 33 34 35 36 37 38 |
# File 'lib/ccrypto/java/data_conversion.rb', line 32 def to_str(bin) if bin.is_a?(::Java::byte[]) String.from_java_bytes(bin) else bin end end |